Open MosheElisha opened 3 years ago
Hi @wing328 ,
Can you please review the feature request or add relevant reviewers?
Thanks.
As discussed I prefer something simple so revising the exception message with additional information such as HTTP response body is fine with me.
Is your feature request related to a problem? Please describe.
When an exception is thrown from the xxxApi classes, the response body is stored in the exception but is not part of the message. In many cases, the body is important and contains the reason of the error. The current implementation requires us to wrap every API call with try-catch that thrown a wrapping exception with the body in the message.
Describe the solution you'd like
Create an ExceptionHandler interface to allow user to replace the exceptions thrown and add a default ExceptionHandlerImpl that keeps the current behavior. Something like:
The user will be able to replace the exception handler implementation by setting the exception handler on the ApiClient. Similar to how it works with the request and response interceptors.
Describe alternatives you've considered
A simpler alternative which is also fine by me is to simple concatenate the body to the message when creating the exception but I'm not sure everyone would like that behavior (especially if it changes past behavior).
Create a custom template but than you need to make sure to keep your template up-to-date when upgrading OpenAPI.
Additional context
ApiClient:
PostsApi:
Default implementation:
Usage example: