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

Introduced NetworkError and BackendError #1437

Merged
merged 2 commits into from
Apr 12, 2022
Merged

Commits on Apr 12, 2022

  1. Introduced NetworkError and BackendError

    - Each layer (only a few for now) has its own error type: `NetworkError`, `BackendError`.
    - `HTTPClient` for example has to produce `NetworkError`, operations produce `BackendError`
    
    ```diff
    struct HTTPResponse<Body: HTTPResponseBody> {
    -   typealias Result = Swift.Result<Self, Error>
    +   typealias Result = Swift.Result<Self, NetworkError>
    }
    ```
    
    - 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`
    - Tests also become simpler:
    
    ```diff
    -        expect(receivedError?.domain).toEventually(equal(RCPurchasesErrorCodeDomain))
    -        expect(receivedError?.code).toEventually(
    -            equal(ErrorCode.unexpectedBackendResponseError.rawValue))
    -        expect(receivedUnderlyingError?.code).toEventually(
    -            equal(UnexpectedBackendResponseSubErrorCode.postOfferIdMissingOffersInResponse.rawValue))
    +
    +        expect(receivedError) == .unexpectedBackendResponse(.postOfferIdMissingOffersInResponse)
    ```
    - Converted `DNSError` into `NetworkError.dnsError`. Its functionality remains unchanged.
    - Removed `Backend.RCSuccessfullySyncedKey` and `ErrorDetails.finishableKey` in favor of tested properties on `NetworkError`
    NachoSoto committed Apr 12, 2022
    Configuration menu
    Copy the full SHA
    7bdd49b View commit details
    Browse the repository at this point in the history
  2. Code review comments

    NachoSoto committed Apr 12, 2022
    Configuration menu
    Copy the full SHA
    e570b81 View commit details
    Browse the repository at this point in the history