summaryrefslogtreecommitdiff
path: root/app_expo/services/api/api-problem.ts
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2021-07-23 15:24:35 +0200
committerThomas F. K. Jorna <[email protected]>2021-07-23 15:24:35 +0200
commit356381d14cb1ff3cbd39c7e396dd14379336451b (patch)
treea03e9b2534600bde7b3b781411b5b03f8134904b /app_expo/services/api/api-problem.ts
parent7aa007f158a52b41494049a1202938fc97813ec1 (diff)
parent73308af061af5e17ac7d4a73fa027a2f303c70dd (diff)
resolving merge conflicts
Diffstat (limited to 'app_expo/services/api/api-problem.ts')
-rw-r--r--app_expo/services/api/api-problem.ts74
1 files changed, 0 insertions, 74 deletions
diff --git a/app_expo/services/api/api-problem.ts b/app_expo/services/api/api-problem.ts
deleted file mode 100644
index 15ca850..0000000
--- a/app_expo/services/api/api-problem.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-import { ApiResponse } from 'apisauce'
-
-export type GeneralApiProblem =
- /**
- * Times up.
- */
- | { kind: 'timeout'; temporary: true }
- /**
- * Cannot connect to the server for some reason.
- */
- | { kind: 'cannot-connect'; temporary: true }
- /**
- * The server experienced a problem. Any 5xx error.
- */
- | { kind: 'server' }
- /**
- * We're not allowed because we haven't identified ourself. This is 401.
- */
- | { kind: 'unauthorized' }
- /**
- * We don't have access to perform that request. This is 403.
- */
- | { kind: 'forbidden' }
- /**
- * Unable to find that resource. This is a 404.
- */
- | { kind: 'not-found' }
- /**
- * All other 4xx series errors.
- */
- | { kind: 'rejected' }
- /**
- * Something truly unexpected happened. Most likely can try again. This is a catch all.
- */
- | { kind: 'unknown'; temporary: true }
- /**
- * The data we received is not in the expected format.
- */
- | { kind: 'bad-data' }
-
-/**
- * Attempts to get a common cause of problems from an api response.
- *
- * @param response The api response.
- */
-export function getGeneralApiProblem(response: ApiResponse<any>): GeneralApiProblem | void {
- switch (response.problem) {
- case 'CONNECTION_ERROR':
- return { kind: 'cannot-connect', temporary: true }
- case 'NETWORK_ERROR':
- return { kind: 'cannot-connect', temporary: true }
- case 'TIMEOUT_ERROR':
- return { kind: 'timeout', temporary: true }
- case 'SERVER_ERROR':
- return { kind: 'server' }
- case 'UNKNOWN_ERROR':
- return { kind: 'unknown', temporary: true }
- case 'CLIENT_ERROR':
- switch (response.status) {
- case 401:
- return { kind: 'unauthorized' }
- case 403:
- return { kind: 'forbidden' }
- case 404:
- return { kind: 'not-found' }
- default:
- return { kind: 'rejected' }
- }
- case 'CANCEL_ERROR':
- return null
- }
-
- return null
-}