import { ApiResponse } from "apisauce" ; export type GeneralApiProblem = { kind : "timeout" ; temporary : true ; } | { kind : "cannot-connect" ; temporary : true ; } | { kind : "server" ; } | { kind : "unauthorized" ; } | { kind : "forbidden" ; } | { kind : "not-found" ; } | { kind : "rejected" ; } | { kind : "unknown" ; temporary : true ; } | { kind : "bad-data" ; } ; param response export function getGeneralApiProblem ( response ) { 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 ; }