-
Notifications
You must be signed in to change notification settings - Fork 316
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
Created ErrorResponse
to abstract error deserialization
#1427
Conversation
3dee0c7
to
e2af00b
Compare
@@ -17,11 +17,8 @@ enum UserInfoAttributeParser { | |||
|
|||
static func attributesUserInfoFromResponse(response: [String: Any], statusCode: HTTPStatusCode) -> [String: Any] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole class will go away soon, will be superseded by the new ErrorResponse
.
f78f584
to
f1efdc8
Compare
// MARK: - | ||
|
||
/// The response content of a failed request. | ||
struct ErrorResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!!! this will also help us get rid of some hacky stuff we have like the finishableKey
and RCSuccessfullySyncedKey
, which were just awkward ways to communicate information through the same existing dictionary back to other layers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
var isSuccessfullySynced: Bool { | ||
return !(self.isServerError || self == .notFoundError) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
36cf996
to
b1ebd78
Compare
8f5e21d
to
3ce751a
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`.
101a97a
to
cd7a551
Compare
3ce751a
to
8c7435c
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`.
cd7a551
to
7b42026
Compare
8c7435c
to
37d47e9
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`.
This is duplicated in most of the `NetworkOperation`s. This new shared implementation will be used by `HTTPClient`.
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`.
…1429) Follow up to #1427. The new way to create errors is like this: ```swift ErrorResponse .from(response) .asBackendError(with: statusCode) ``` ## 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`.
…rkError` and `BackendError` (#1425) Closes #695 and finishes [CF-195]. Depends on ~~#1431, #1432, #1433, #1437~~. ## Goals: - [x] Handle all requests / response / deserialization errors in `HTTPClient`. Clients of `HTTPClient` will only have to handle the "happy" path: #1431 - [x] `HTTPClient` shouldn't return `Result.success` with failed responses, forcing clients to verify the response is actually a failure: #1431 - [x] Abstract error response deserialization / error creation: #1427 - [x] Abstract attribute error parsing: #1427 - [x] Move response deserialization to `HTTPClient` based on a `ResponseType: Decodable` type, so the completion block will simply return a `Result<HTTPResponse<ResponseType>, Error>` - [x] `ETagManager` should store response `Data` instead of a deserialized `[String: Any]` - [x] Improved error types in `HTTPClient` to fix tests: #1437 - [x] Dealt with non-backwards compatible `ETagManager: #1438 ## Changes: - Replaced `HTTPResponse`'s body from `[String: Any]` to a generic `HTTPResponseBody`. - Created `HTTPResponseBody` to abstract `Decodable` and provide some default implementations for types like `Data,` `[String: Any]` (for backwards compatibility to types that aren't `Decodable` yet), and `Decodable` itself. - New `HTTPResponse.Result` typealias (`Result<HTTPResponse<HTTPResponseBody>, Error>`) used everywhere. This will allow replacing `Error` with a more specific `Error` so we can forward known typed errors, and make sure that we don't end up with the wrong error type, or with a very complex error hierarchy and the details buried in `underlyingError`. - Each layer (only a few for now) has its own error type: `NetworkError`, `BackendError`, `OfferingsManager.Error`. - `HTTPClient` for example has to produce `NetworkError`, operations produce `BackendError` - The parent `BackendError` can have specific errors like `.missingAppUserID`, but also be simply a child error `case networkError(NetworkError)` - All of these conform to a `ErrorCodeConvertible`, so there is a single point of code that converts from simple and readable errors (like `BackendError.emptySubscriberAttributes`, `.unexpectedBackendResponse(.loginResponseDecoding)`) into errors with all the context using `ErrorUtils` - Converted `DNSError` into `NetworkError.dnsError`. Its functionality remains unchanged. - Removed `Backend.RCSuccessfullySyncedKey` and `ErrorDetails.finishableKey` in favor of tested properties on `NetworkError` ### Leftovers There's a few things I've decided to not finish for now: - [ ] `CustomerInfo` still does't conform to `Decodable` (manual deserialization is still supported by the current system): #1496 - `SubscriberAttributeDict` could also be `Codable` - [x] Replace `OfferingsFactory` with `Decodable`: #1435 [CF-195]: https://revenuecats.atlassian.net/browse/CF-195?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
This is duplicated in most of the
NetworkOperation
s. This new shared implementation will be used byHTTPClient
.For #695.
See #1429 for how this is used.