This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): Add 404 error translation (#141) by @bryanstearns
- Loading branch information
1 parent
e3844cf
commit 0369a23
Showing
3 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { getGeneralApiProblem } from "./api-problem" | ||
import { ApiErrorResponse } from "apisauce" | ||
|
||
test("handles connection errors", () => { | ||
expect(getGeneralApiProblem({ problem: "CONNECTION_ERROR" } as ApiErrorResponse<null>)).toEqual({ | ||
kind: "cannot-connect", | ||
temporary: true, | ||
}) | ||
}) | ||
|
||
test("handles network errors", () => { | ||
expect(getGeneralApiProblem({ problem: "NETWORK_ERROR" } as ApiErrorResponse<null>)).toEqual({ | ||
kind: "cannot-connect", | ||
temporary: true, | ||
}) | ||
}) | ||
|
||
test("handles timeouts", () => { | ||
expect(getGeneralApiProblem({ problem: "TIMEOUT_ERROR" } as ApiErrorResponse<null>)).toEqual({ | ||
kind: "timeout", | ||
temporary: true, | ||
}) | ||
}) | ||
|
||
test("handles server errors", () => { | ||
expect(getGeneralApiProblem({ problem: "SERVER_ERROR" } as ApiErrorResponse<null>)).toEqual({ | ||
kind: "server", | ||
}) | ||
}) | ||
|
||
test("handles unknown errors", () => { | ||
expect(getGeneralApiProblem({ problem: "UNKNOWN_ERROR" } as ApiErrorResponse<null>)).toEqual({ | ||
kind: "unknown", | ||
temporary: true, | ||
}) | ||
}) | ||
|
||
test("handles unauthorized errors", () => { | ||
expect( | ||
getGeneralApiProblem({ problem: "CLIENT_ERROR", status: 401 } as ApiErrorResponse<null>), | ||
).toEqual({ | ||
kind: "unauthorized", | ||
}) | ||
}) | ||
|
||
test("handles forbidden errors", () => { | ||
expect( | ||
getGeneralApiProblem({ problem: "CLIENT_ERROR", status: 403 } as ApiErrorResponse<null>), | ||
).toEqual({ | ||
kind: "forbidden", | ||
}) | ||
}) | ||
|
||
test("handles not-found errors", () => { | ||
expect( | ||
getGeneralApiProblem({ problem: "CLIENT_ERROR", status: 404 } as ApiErrorResponse<null>), | ||
).toEqual({ | ||
kind: "not-found", | ||
}) | ||
}) | ||
|
||
test("handles other client errors", () => { | ||
expect( | ||
getGeneralApiProblem({ problem: "CLIENT_ERROR", status: 418 } as ApiErrorResponse<null>), | ||
).toEqual({ | ||
kind: "rejected", | ||
}) | ||
}) | ||
|
||
test("handles cancellation errors", () => { | ||
expect(getGeneralApiProblem({ problem: "CANCEL_ERROR" } as ApiErrorResponse<null>)).toBeNull() | ||
}) |
This file contains 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
This file contains 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