Improve error handling in CompanyLogosService by extracting detailed messages from ApiException responses

This commit is contained in:
2026-06-04 12:26:36 +01:00
parent 520020dab0
commit 5d617e1025

View File

@@ -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;
}
}