From 725ca2f138f2cd2f94769a6ff0e401ace061f1fc Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 11 Jun 2026 18:59:07 +0100 Subject: [PATCH] refactor: standardize error handling by extracting detailed messages from ApiException --- Marechai/Services/CollectionService.cs | 34 ++++-- Marechai/Services/CompaniesService.cs | 37 ++++--- Marechai/Services/GpuPhotosService.cs | 26 +++++ Marechai/Services/GpusService.cs | 40 ++++--- Marechai/Services/InstructionSetsService.cs | 26 +++-- Marechai/Services/MachinePhotosService.cs | 26 +++++ Marechai/Services/MachinesService.cs | 102 ++++++++++-------- Marechai/Services/MessagingService.cs | 14 +++ Marechai/Services/ProcessorPhotosService.cs | 26 +++++ Marechai/Services/ProcessorsService.cs | 42 +++++--- .../Services/SoftwareAttributesService.cs | 14 +++ Marechai/Services/SoftwareReleasesService.cs | 84 +++++++++------ Marechai/Services/SoftwareService.cs | 14 +++ Marechai/Services/SoundSynthPhotosService.cs | 26 +++++ Marechai/Services/SoundSynthsService.cs | 14 +++ 15 files changed, 384 insertions(+), 141 deletions(-) diff --git a/Marechai/Services/CollectionService.cs b/Marechai/Services/CollectionService.cs index abb6dbf8..83074b1a 100644 --- a/Marechai/Services/CollectionService.cs +++ b/Marechai/Services/CollectionService.cs @@ -153,7 +153,7 @@ public sealed class CollectionService(Client client, ILogger { logger.LogError(ex, "API error adding book {BookId} to collection", bookId); - return (false, ex.Message); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -175,7 +175,7 @@ public sealed class CollectionService(Client client, ILogger { logger.LogError(ex, "API error removing book {BookId} from collection", bookId); - return (false, ex.Message); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -215,7 +215,7 @@ public sealed class CollectionService(Client client, ILogger { logger.LogError(ex, "API error adding document {DocumentId} to collection", documentId); - return (false, ex.Message); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -237,7 +237,7 @@ public sealed class CollectionService(Client client, ILogger { logger.LogError(ex, "API error removing document {DocumentId} from collection", documentId); - return (false, ex.Message); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -277,7 +277,7 @@ public sealed class CollectionService(Client client, ILogger { logger.LogError(ex, "API error adding machine {MachineId} to collection", machineId); - return (false, ex.Message); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -299,7 +299,7 @@ public sealed class CollectionService(Client client, ILogger { logger.LogError(ex, "API error removing machine {MachineId} from collection", machineId); - return (false, ex.Message); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -339,7 +339,7 @@ public sealed class CollectionService(Client client, ILogger { logger.LogError(ex, "API error adding software release {ReleaseId} to collection", releaseId); - return (false, ex.Message); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -361,7 +361,7 @@ public sealed class CollectionService(Client client, ILogger { logger.LogError(ex, "API error removing software release {ReleaseId} from collection", releaseId); - return (false, ex.Message); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -401,7 +401,7 @@ public sealed class CollectionService(Client client, ILogger { logger.LogError(ex, "API error adding magazine issue {IssueId} to collection", issueId); - return (false, ex.Message); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -423,7 +423,7 @@ public sealed class CollectionService(Client client, ILogger { logger.LogError(ex, "API error removing magazine issue {IssueId} from collection", issueId); - return (false, ex.Message); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -431,5 +431,19 @@ public sealed class CollectionService(Client client, ILogger return (false, ex.Message); } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } } diff --git a/Marechai/Services/CompaniesService.cs b/Marechai/Services/CompaniesService.cs index 84457f68..0429a46a 100644 --- a/Marechai/Services/CompaniesService.cs +++ b/Marechai/Services/CompaniesService.cs @@ -109,8 +109,8 @@ public class CompaniesService(Marechai.ApiClient.Client client, ReferenceDataCac return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -129,8 +129,8 @@ public class CompaniesService(Marechai.ApiClient.Client client, ReferenceDataCac return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -147,8 +147,8 @@ public class CompaniesService(Marechai.ApiClient.Client client, ReferenceDataCac return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -231,8 +231,8 @@ public class CompaniesService(Marechai.ApiClient.Client client, ReferenceDataCac return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -249,8 +249,8 @@ public class CompaniesService(Marechai.ApiClient.Client client, ReferenceDataCac return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -464,13 +464,24 @@ public class CompaniesService(Marechai.ApiClient.Client client, ReferenceDataCac } catch(ApiException ex) { - string detail = ex is ProblemDetails pd ? pd.Detail ?? pd.Title ?? ex.Message : ex.Message; - - return (false, detail); + return (false, ExtractDetail(ex)); } catch(Exception ex) { return (false, ex.Message); } } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; + } } diff --git a/Marechai/Services/GpuPhotosService.cs b/Marechai/Services/GpuPhotosService.cs index a2c84968..bc73eb62 100644 --- a/Marechai/Services/GpuPhotosService.cs +++ b/Marechai/Services/GpuPhotosService.cs @@ -105,6 +105,10 @@ public class GpuPhotosService(Marechai.ApiClient.Client client, IRequestAdapter return (result, null); } + catch(ApiException ex) + { + return (null, ExtractDetail(ex)); + } catch(Exception ex) { return (null, ex.Message); @@ -119,6 +123,10 @@ public class GpuPhotosService(Marechai.ApiClient.Client client, IRequestAdapter return (true, null); } + catch(ApiException ex) + { + return (false, ExtractDetail(ex)); + } catch(Exception ex) { return (false, ex.Message); @@ -180,6 +188,10 @@ public class GpuPhotosService(Marechai.ApiClient.Client client, IRequestAdapter await client.Gpus.Photos.Admin.Batch.Commit.PostAsync(request); return (job, null); } + catch(ApiException ex) + { + return (null, ExtractDetail(ex)); + } catch(Exception ex) { return (null, ex.Message); @@ -201,5 +213,19 @@ public class GpuPhotosService(Marechai.ApiClient.Client client, IRequestAdapter { return null; } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } } diff --git a/Marechai/Services/GpusService.cs b/Marechai/Services/GpusService.cs index 1c97f8bf..14c6220d 100644 --- a/Marechai/Services/GpusService.cs +++ b/Marechai/Services/GpusService.cs @@ -148,7 +148,7 @@ public class GpusService(Marechai.ApiClient.Client client, IndexNowService index } catch(ApiException ex) { - return (null, ExtractErrorMessage(ex)); + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -168,7 +168,7 @@ public class GpusService(Marechai.ApiClient.Client client, IndexNowService index } catch(ApiException ex) { - return (false, ExtractErrorMessage(ex)); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -186,7 +186,7 @@ public class GpusService(Marechai.ApiClient.Client client, IndexNowService index } catch(ApiException ex) { - return (false, ExtractErrorMessage(ex)); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -233,7 +233,7 @@ public class GpusService(Marechai.ApiClient.Client client, IndexNowService index } catch(ApiException ex) { - return (null, ExtractErrorMessage(ex)); + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -251,7 +251,7 @@ public class GpusService(Marechai.ApiClient.Client client, IndexNowService index } catch(ApiException ex) { - return (false, ExtractErrorMessage(ex)); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -362,7 +362,7 @@ public class GpusService(Marechai.ApiClient.Client client, IndexNowService index } catch(ApiException ex) { - return (false, ExtractErrorMessage(ex)); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -380,7 +380,7 @@ public class GpusService(Marechai.ApiClient.Client client, IndexNowService index } catch(ApiException ex) { - return (false, ExtractErrorMessage(ex)); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -390,12 +390,6 @@ public class GpusService(Marechai.ApiClient.Client client, IndexNowService index // ── Videos ── - static string ExtractErrorMessage(ApiException ex) - { - if(ex is ProblemDetails pd) return pd.Detail ?? pd.Title ?? ex.Message; - - return ex.Message; - } public async Task> GetVideosByGpuAsync(int gpuId) { @@ -429,7 +423,7 @@ public class GpusService(Marechai.ApiClient.Client client, IndexNowService index } catch(ApiException ex) { - return (null, ExtractErrorMessage(ex)); + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -450,7 +444,7 @@ public class GpusService(Marechai.ApiClient.Client client, IndexNowService index } catch(ApiException ex) { - return (false, ExtractErrorMessage(ex)); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -468,11 +462,25 @@ public class GpusService(Marechai.ApiClient.Client client, IndexNowService index } catch(ApiException ex) { - return (false, ExtractErrorMessage(ex)); + return (false, ExtractDetail(ex)); } catch(Exception ex) { return (false, ex.Message); } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } } diff --git a/Marechai/Services/InstructionSetsService.cs b/Marechai/Services/InstructionSetsService.cs index e4e39ad1..3fddb390 100644 --- a/Marechai/Services/InstructionSetsService.cs +++ b/Marechai/Services/InstructionSetsService.cs @@ -68,8 +68,8 @@ public class InstructionSetsService(Marechai.ApiClient.Client client) return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -86,8 +86,8 @@ public class InstructionSetsService(Marechai.ApiClient.Client client) return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -104,8 +104,8 @@ public class InstructionSetsService(Marechai.ApiClient.Client client) return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -125,5 +125,19 @@ public class InstructionSetsService(Marechai.ApiClient.Client client) { return false; } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } } diff --git a/Marechai/Services/MachinePhotosService.cs b/Marechai/Services/MachinePhotosService.cs index aba5b8b1..f5ee3a66 100644 --- a/Marechai/Services/MachinePhotosService.cs +++ b/Marechai/Services/MachinePhotosService.cs @@ -105,6 +105,10 @@ public class MachinePhotosService(Marechai.ApiClient.Client client, IRequestAdap return (result, null); } + catch(ApiException ex) + { + return (null, ExtractDetail(ex)); + } catch(Exception ex) { return (null, ex.Message); @@ -119,6 +123,10 @@ public class MachinePhotosService(Marechai.ApiClient.Client client, IRequestAdap return (true, null); } + catch(ApiException ex) + { + return (false, ExtractDetail(ex)); + } catch(Exception ex) { return (false, ex.Message); @@ -192,6 +200,10 @@ public class MachinePhotosService(Marechai.ApiClient.Client client, IRequestAdap await client.Machines.Photos.Admin.Batch.Commit.PostAsync(request); return (job, null); } + catch(ApiException ex) + { + return (null, ExtractDetail(ex)); + } catch(Exception ex) { return (null, ex.Message); @@ -213,5 +225,19 @@ public class MachinePhotosService(Marechai.ApiClient.Client client, IRequestAdap { return null; } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } } diff --git a/Marechai/Services/MachinesService.cs b/Marechai/Services/MachinesService.cs index f6a964dd..8fbb53f8 100644 --- a/Marechai/Services/MachinesService.cs +++ b/Marechai/Services/MachinesService.cs @@ -35,12 +35,6 @@ namespace Marechai.Services; public class MachinesService(Marechai.ApiClient.Client client, IndexNowService indexNow) { - static string ExtractErrorMessage(ApiException ex) - { - if(ex is ProblemDetails pd) return pd.Detail ?? pd.Title ?? ex.Message; - - return ex.Message; - } public async Task GetMachine(int id) { try @@ -139,8 +133,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -159,8 +153,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -177,8 +171,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -264,8 +258,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -282,8 +276,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -329,8 +323,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -347,8 +341,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -394,8 +388,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -412,8 +406,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -459,8 +453,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -477,8 +471,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -510,8 +504,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -528,8 +522,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -561,8 +555,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -579,8 +573,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -684,8 +678,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -702,8 +696,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -773,8 +767,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -791,8 +785,8 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -834,7 +828,7 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i } catch(ApiException ex) { - return (null, ExtractErrorMessage(ex)); + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -855,7 +849,7 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i } catch(ApiException ex) { - return (false, ExtractErrorMessage(ex)); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -873,11 +867,25 @@ public class MachinesService(Marechai.ApiClient.Client client, IndexNowService i } catch(ApiException ex) { - return (false, ExtractErrorMessage(ex)); + return (false, ExtractDetail(ex)); } catch(Exception ex) { return (false, ex.Message); } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } } diff --git a/Marechai/Services/MessagingService.cs b/Marechai/Services/MessagingService.cs index 8d23f93c..aeb56a3d 100644 --- a/Marechai/Services/MessagingService.cs +++ b/Marechai/Services/MessagingService.cs @@ -362,5 +362,19 @@ public class MessagingService(Marechai.ApiClient.Client client) { return (false, ex.Message); } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } } diff --git a/Marechai/Services/ProcessorPhotosService.cs b/Marechai/Services/ProcessorPhotosService.cs index 377b0580..88493bd3 100644 --- a/Marechai/Services/ProcessorPhotosService.cs +++ b/Marechai/Services/ProcessorPhotosService.cs @@ -105,6 +105,10 @@ public class ProcessorPhotosService(Marechai.ApiClient.Client client, IRequestAd return (result, null); } + catch(ApiException ex) + { + return (null, ExtractDetail(ex)); + } catch(Exception ex) { return (null, ex.Message); @@ -119,6 +123,10 @@ public class ProcessorPhotosService(Marechai.ApiClient.Client client, IRequestAd return (true, null); } + catch(ApiException ex) + { + return (false, ExtractDetail(ex)); + } catch(Exception ex) { return (false, ex.Message); @@ -180,6 +188,10 @@ public class ProcessorPhotosService(Marechai.ApiClient.Client client, IRequestAd await client.Processors.Photos.Admin.Batch.Commit.PostAsync(request); return (job, null); } + catch(ApiException ex) + { + return (null, ExtractDetail(ex)); + } catch(Exception ex) { return (null, ex.Message); @@ -201,5 +213,19 @@ public class ProcessorPhotosService(Marechai.ApiClient.Client client, IRequestAd { return null; } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } } diff --git a/Marechai/Services/ProcessorsService.cs b/Marechai/Services/ProcessorsService.cs index 70f69259..7b638a64 100644 --- a/Marechai/Services/ProcessorsService.cs +++ b/Marechai/Services/ProcessorsService.cs @@ -147,8 +147,8 @@ public class ProcessorsService(Marechai.ApiClient.Client client, IndexNowService return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -167,8 +167,8 @@ public class ProcessorsService(Marechai.ApiClient.Client client, IndexNowService return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -185,8 +185,8 @@ public class ProcessorsService(Marechai.ApiClient.Client client, IndexNowService return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -285,8 +285,8 @@ public class ProcessorsService(Marechai.ApiClient.Client client, IndexNowService return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -303,8 +303,8 @@ public class ProcessorsService(Marechai.ApiClient.Client client, IndexNowService return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -374,8 +374,8 @@ public class ProcessorsService(Marechai.ApiClient.Client client, IndexNowService return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -392,8 +392,8 @@ public class ProcessorsService(Marechai.ApiClient.Client client, IndexNowService return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -487,5 +487,19 @@ public class ProcessorsService(Marechai.ApiClient.Client client, IndexNowService { return (false, ex.Message); } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } } diff --git a/Marechai/Services/SoftwareAttributesService.cs b/Marechai/Services/SoftwareAttributesService.cs index 1ec2fcfd..df1900c0 100644 --- a/Marechai/Services/SoftwareAttributesService.cs +++ b/Marechai/Services/SoftwareAttributesService.cs @@ -243,5 +243,19 @@ public class SoftwareAttributesService(Marechai.ApiClient.Client client) { return (null, ex.Message); } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } } diff --git a/Marechai/Services/SoftwareReleasesService.cs b/Marechai/Services/SoftwareReleasesService.cs index 23a05036..9d7fa02d 100644 --- a/Marechai/Services/SoftwareReleasesService.cs +++ b/Marechai/Services/SoftwareReleasesService.cs @@ -83,8 +83,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -101,8 +101,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -119,8 +119,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -154,8 +154,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -172,8 +172,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -207,8 +207,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (id, null); } catch(ApiException ex) - { - return (null, ex.Message); + { + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -225,8 +225,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -260,8 +260,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -278,8 +278,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -313,8 +313,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -331,8 +331,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -366,8 +366,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -384,8 +384,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -547,8 +547,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -565,8 +565,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -760,8 +760,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -778,8 +778,8 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference return (true, null); } catch(ApiException ex) - { - return (false, ex.Message); + { + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -911,7 +911,7 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference } catch(ApiException ex) { - return (null, ex is ProblemDetails pd ? (pd.Detail ?? pd.Title ?? ex.Message) : ex.Message); + return (null, ExtractDetail(ex)); } catch(Exception ex) { @@ -934,5 +934,19 @@ public class SoftwareReleasesService(Marechai.ApiClient.Client client, Reference { return null; } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } } diff --git a/Marechai/Services/SoftwareService.cs b/Marechai/Services/SoftwareService.cs index 5b2a7c9f..d9554271 100644 --- a/Marechai/Services/SoftwareService.cs +++ b/Marechai/Services/SoftwareService.cs @@ -2431,5 +2431,19 @@ public class SoftwareService(Marechai.ApiClient.Client client, IRequestAdapter r { return (false, ex.Message); } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } } diff --git a/Marechai/Services/SoundSynthPhotosService.cs b/Marechai/Services/SoundSynthPhotosService.cs index d8dc7d6f..51f85717 100644 --- a/Marechai/Services/SoundSynthPhotosService.cs +++ b/Marechai/Services/SoundSynthPhotosService.cs @@ -105,6 +105,10 @@ public class SoundSynthPhotosService(Marechai.ApiClient.Client client, IRequestA return (result, null); } + catch(ApiException ex) + { + return (null, ExtractDetail(ex)); + } catch(Exception ex) { return (null, ex.Message); @@ -119,6 +123,10 @@ public class SoundSynthPhotosService(Marechai.ApiClient.Client client, IRequestA return (true, null); } + catch(ApiException ex) + { + return (false, ExtractDetail(ex)); + } catch(Exception ex) { return (false, ex.Message); @@ -180,6 +188,10 @@ public class SoundSynthPhotosService(Marechai.ApiClient.Client client, IRequestA await client.SoundSynths.Photos.Admin.Batch.Commit.PostAsync(request); return (job, null); } + catch(ApiException ex) + { + return (null, ExtractDetail(ex)); + } catch(Exception ex) { return (null, ex.Message); @@ -201,5 +213,19 @@ public class SoundSynthPhotosService(Marechai.ApiClient.Client client, IRequestA { return null; } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } } diff --git a/Marechai/Services/SoundSynthsService.cs b/Marechai/Services/SoundSynthsService.cs index 279ff81b..29074314 100644 --- a/Marechai/Services/SoundSynthsService.cs +++ b/Marechai/Services/SoundSynthsService.cs @@ -399,5 +399,19 @@ public class SoundSynthsService(Marechai.ApiClient.Client client, IndexNowServic { return (false, ex.Message); } + + } + + static string ExtractDetail(ApiException ex) + { + if(ex is ProblemDetails pd) + { + if(!string.IsNullOrWhiteSpace(pd.Detail)) return pd.Detail; + if(!string.IsNullOrWhiteSpace(pd.Title)) return pd.Title; + } + + if(ex is { ResponseStatusCode: 0 } || string.IsNullOrWhiteSpace(ex.Message)) return "Unknown error"; + + return ex.Message; } }