Externalize error messages

This commit is contained in:
Eike Kettner
2021-04-17 11:14:29 +02:00
parent c9b54e80b7
commit b2cffb22ef
65 changed files with 1518 additions and 683 deletions

View File

@ -17,6 +17,11 @@ import Process
import Task exposing (Task)
errorToString : Http.Error -> String
errorToString _ =
Debug.todo "remove me"
-- Authenticated Requests
@ -138,45 +143,6 @@ authDelete req =
-- Error Utilities
errorToStringStatus : Http.Error -> (Int -> String) -> String
errorToStringStatus error statusString =
case error of
Http.BadUrl url ->
"There is something wrong with this url: " ++ url
Http.Timeout ->
"There was a network timeout."
Http.NetworkError ->
"There was a network error."
Http.BadStatus status ->
statusString status
Http.BadBody str ->
"There was an error decoding the response: " ++ str
errorToString : Http.Error -> String
errorToString error =
let
f sc =
if sc == 404 then
"The requested resource doesn't exist."
else if sc >= 400 && sc < 500 then
"Invalid input when processing the request."
else
"There was an invalid response status: " ++ String.fromInt sc ++ "."
in
errorToStringStatus error f
-- Http.Task Utilities

View File

@ -0,0 +1,11 @@
module Util.Result exposing (fold)
fold : (a -> x) -> (b -> x) -> Result b a -> x
fold fa fb rba =
case rba of
Ok a ->
fa a
Err b ->
fb b