mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 10:58:26 +00:00
Externalize error messages
This commit is contained in:
@ -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
|
||||
|
||||
|
||||
|
11
modules/webapp/src/main/elm/Util/Result.elm
Normal file
11
modules/webapp/src/main/elm/Util/Result.elm
Normal 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
|
Reference in New Issue
Block a user