Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support returning api response in case of deserialization exception #1167

Conversation

james-s-tayler
Copy link
Contributor

@james-s-tayler james-s-tayler commented May 8, 2021

What kind of change does this PR introduce?
This is a bug fix for #1160 and #1017 - ApiResponse wasn't trapping exceptions that occurred while attempting to deserialize the response, which violated the expectations of the ApiResponse programming model.

What is the current behavior?
The current behavior is that an ApiResponse will throw a Refit.ApiException if an exception is thrown while attempting to deserialize the response.

What is the new behavior?
The deserialization exception is properly wrapped by a Refit.ApiException and returned in the ApiResponse

What might this PR break?
I've added tests for this and ensured the existing tests for the non ApiResponse case still pass. If callers knew about the current behavior and had explicit try/catch blocks those will no longer be invoked anymore. Though, all callers will almost certainly have existing exception handling logic for the ApiResponse which should pick up the deserialization exceptions now too. I, for one, didn't realize the library behaved as it does at present and expected every and all exception to come back via ApiResponse.Error.

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

@james-s-tayler
Copy link
Contributor Author

james-s-tayler commented May 8, 2021

Also @clairernovotny I noticed while putting this together that ApiResponse doesn't seem to support ValidationApiException either... I didn't finish going all the way down the rabbit hole of why but it seems related to it being a subclass of ApiException. I would somewhat prefer a design whereby the details that ValidationApiException exposes live as an inner exception inside of ApiException as having two top-level exceptions here means more try/catch and IMO violates the principle of least surprise. Thoughts?

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants