From 5d617e10259cbcd80512bbe0a0d30cf5319bdaf4 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 4 Jun 2026 12:26:36 +0100 Subject: [PATCH] Improve error handling in CompanyLogosService by extracting detailed messages from ApiException responses --- Marechai/Services/CompanyLogosService.cs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Marechai/Services/CompanyLogosService.cs b/Marechai/Services/CompanyLogosService.cs index 4218a464..e09b2392 100644 --- a/Marechai/Services/CompanyLogosService.cs +++ b/Marechai/Services/CompanyLogosService.cs @@ -61,7 +61,7 @@ public class CompanyLogosService(Marechai.ApiClient.Client client, IRequestAdapt } catch(ApiException ex) { - return (false, ex.Message); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -84,7 +84,7 @@ public class CompanyLogosService(Marechai.ApiClient.Client client, IRequestAdapt } catch(ApiException ex) { - return (false, ex.Message); + return (false, ExtractDetail(ex)); } catch(Exception ex) { @@ -124,11 +124,28 @@ public class CompanyLogosService(Marechai.ApiClient.Client client, IRequestAdapt } catch(ApiException ex) { - return (null, ex.Message); + return (null, ExtractDetail(ex)); } catch(Exception ex) { return (null, ex.Message); } } + + static string ExtractDetail(ApiException ex) + { + // Kiota maps server error responses to a typed ProblemDetails (which inherits from + // ApiException). The base Exception.Message just returns "Exception of type 'X' was + // thrown." — the real, user-facing text lives on Detail / Title. Surface those when + // present, falling back to Message only if the server gave us nothing useful. + 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; + } }