mirror of
https://github.com/claunia/marechai.git
synced 2026-07-08 17:57:08 +00:00
Improve error handling in CompanyLogosService by extracting detailed messages from ApiException responses
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user