Replaced manual error response deserialization with ErrorResponse#1429
Merged
Conversation
NachoSoto
commented
Mar 30, 2022
Contributor
Author
There was a problem hiding this comment.
This decode method mutates the instance it's called on, which isn't a great practice. At least the keyDecodingStrategy is no longer changed and we rely on a single defaultJsonDecoder everywhere. I should look at the date and data decoding strategies, we might be able to just set them on defaultJsonDecoder too.
NachoSoto
commented
Mar 30, 2022
Contributor
Author
There was a problem hiding this comment.
This was previously handled by UserInfoAttributeParser.
f78f584 to
f1efdc8
Compare
0f4ef59 to
c4830a4
Compare
c4830a4 to
0f99cc1
Compare
8f5e21d to
3ce751a
Compare
0f99cc1 to
09b1496
Compare
NachoSoto
added a commit
that referenced
this pull request
Mar 30, 2022
Follow up to #1429. For #695. This was duplicated in all operations. `HTTPClient` now only forwards `Result.success` if the request actually succeeded, leaving each `NetworkOperation` to just parse the body (which will become part of `HTTPClient` too). Other changes: - Simplified logic for when to retry requests in `HTTPClient` by using a new `Result.asOptionalResult` - Removed several response handlers that don't need to do anything anymore - Removed several tests that were basically duplicated: - The `finishable` checks are already tested as part of `ErrorResponse`. - All the checks for the error details are also part of `ErrorResponse`. - No longer need to have a test for each type of failed response since that's part of `HTTPClient` tests now.
NachoSoto
added a commit
that referenced
this pull request
Mar 30, 2022
Follow up to #1429. The `decode` methods no longer mutate the underlying `JSONDecoder`, and instead the codebase uses a shared `defaultJSONDecoder` with the correct configuration.
taquitos
reviewed
Mar 31, 2022
| : .failure( | ||
| ErrorUtils.backendError(withBackendCode: BackendErrorCode(code: response["code"]), | ||
| backendMessage: response["message"] as? String) | ||
| ErrorResponse |
Contributor
There was a problem hiding this comment.
This is SO much better. I hacked on the errors a bunch just to get it working and surfacing what we wanted to surface, but this is a nice API 🧡
taquitos
approved these changes
Mar 31, 2022
3ce751a to
8c7435c
Compare
09b1496 to
58eac08
Compare
NachoSoto
added a commit
that referenced
this pull request
Apr 1, 2022
Follow up to #1429. For #695. This was duplicated in all operations. `HTTPClient` now only forwards `Result.success` if the request actually succeeded, leaving each `NetworkOperation` to just parse the body (which will become part of `HTTPClient` too). Other changes: - Simplified logic for when to retry requests in `HTTPClient` by using a new `Result.asOptionalResul` - Removed several response handlers that don't need to do anything anymore - Removed several tests that were basically duplicated: - The `finishable` checks are already tested as part of `ErrorResponse`. - All the checks for the error details are also part of `ErrorResponse`. - No longer need to have a test for each type of failed response since that's part of `HTTPClient`tests now.
NachoSoto
added a commit
that referenced
this pull request
Apr 1, 2022
Follow up to #1429. The `decode` methods no longer mutate the underlying `JSONDecoder`, and instead the codebase uses a shared `defaultJSONDecoder` with the correct configuration.
8c7435c to
37d47e9
Compare
58eac08 to
9b707ec
Compare
NachoSoto
added a commit
that referenced
this pull request
Apr 1, 2022
Follow up to #1429. For #695. This was duplicated in all operations. `HTTPClient` now only forwards `Result.success` if the request actually succeeded, leaving each `NetworkOperation` to just parse the body (which will become part of `HTTPClient` too). Other changes: - Simplified logic for when to retry requests in `HTTPClient` by using a new `Result.asOptionalResul` - Removed several response handlers that don't need to do anything anymore - Removed several tests that were basically duplicated: - The `finishable` checks are already tested as part of `ErrorResponse`. - All the checks for the error details are also part of `ErrorResponse`. - No longer need to have a test for each type of failed response since that's part of `HTTPClient`tests now.
NachoSoto
added a commit
that referenced
this pull request
Apr 1, 2022
Follow up to #1429. The `decode` methods no longer mutate the underlying `JSONDecoder`, and instead the codebase uses a shared `defaultJSONDecoder` with the correct configuration.
37d47e9 to
f3946de
Compare
Follow up to #1427. Other changes: - Removed `UserInfoAttributeParser` - Simplified `JSONDecoder.decode` implementation by simply relying on `defaultJsonDecoder` - Added support for "wrapped" error responses. This was previously handled by `UserInfoAttributeParser`. - Removed all duplicated code parsing error responses - The new `ErrorResponse` introduced in #1427 correctly decodes the format sent by the backend. Note that some tests had the wrong format, and `UserInfoAttributeParser` was parsing that wrong as well. An upcoming PR will actually move these calls to `ErrorResponse` to `HTTPClient`.
9b707ec to
3ba81e4
Compare
NachoSoto
added a commit
that referenced
this pull request
Apr 1, 2022
Follow up to #1429. The `decode` methods no longer mutate the underlying `JSONDecoder`, and instead the codebase uses a shared `defaultJSONDecoder` with the correct configuration.
NachoSoto
added a commit
that referenced
this pull request
Apr 1, 2022
Follow up to #1429. The `decode` methods no longer mutate the underlying `JSONDecoder`, and instead the codebase uses a shared `defaultJSONDecoder` with the correct configuration.
NachoSoto
added a commit
that referenced
this pull request
Apr 1, 2022
Follow up to #1429. For #695. This was duplicated in all operations. `HTTPClient` now only forwards `Result.success` if the request actually succeeded, leaving each `NetworkOperation` to just parse the body (which will become part of `HTTPClient` too). Other changes: - Simplified logic for when to retry requests in `HTTPClient` by using a new `Result.asOptionalResul` - Removed several response handlers that don't need to do anything anymore - Removed several tests that were basically duplicated: - The `finishable` checks are already tested as part of `ErrorResponse`. - All the checks for the error details are also part of `ErrorResponse`. - No longer need to have a test for each type of failed response since that's part of `HTTPClient`tests now.
NachoSoto
added a commit
that referenced
this pull request
Apr 5, 2022
Follow up to #1429. For #695. This was duplicated in all operations. `HTTPClient` now only forwards `Result.success` if the request actually succeeded, leaving each `NetworkOperation` to just parse the body (which will become part of `HTTPClient` too). Other changes: - Simplified logic for when to retry requests in `HTTPClient` by using a new `Result.asOptionalResult` - Removed several response handlers that don't need to do anything anymore - Removed several tests that were basically duplicated: - The `finishable` checks are already tested as part of `ErrorResponse`. - All the checks for the error details are also part of `ErrorResponse`. - No longer need to have a test for each type of failed response since that's part of `HTTPClient` tests now.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Follow up to #1427.
The new way to create errors is like this:
Other changes:
UserInfoAttributeParserJSONDecoder.decodeimplementation by simply relying ondefaultJsonDecoderUserInfoAttributeParser.ErrorResponseintroduced in CreatedErrorResponseto abstract error deserialization #1427 correctly decodes the format sent by the backend. Note that some tests had the wrong format, andUserInfoAttributeParserwas parsing that wrong as well.An upcoming PR will actually move these calls to
ErrorResponsetoHTTPClient.