diff options
Diffstat (limited to 'src/client/elm/Utils')
-rw-r--r-- | src/client/elm/Utils/Http.elm | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/client/elm/Utils/Http.elm b/src/client/elm/Utils/Http.elm index 2cf1294..bd6e2ac 100644 --- a/src/client/elm/Utils/Http.elm +++ b/src/client/elm/Utils/Http.elm @@ -1,6 +1,7 @@ module Utils.Http ( post , decodeHttpValue + , errorKey ) where import Http exposing (..) @@ -18,6 +19,12 @@ post url = |> mapError promoteError |> flip Task.andThen handleResponse +promoteError : RawError -> Error +promoteError rawError = + case rawError of + RawTimeout -> Timeout + RawNetworkError -> NetworkError + handleResponse : Response -> Task Error Value handleResponse response = if 200 <= response.status && response.status < 300 @@ -30,12 +37,6 @@ responseString value = Text str -> str _ -> "" -promoteError : RawError -> Error -promoteError rawError = - case rawError of - RawTimeout -> Timeout - RawNetworkError -> NetworkError - decodeHttpValue : Decoder a -> Value -> Task Error a decodeHttpValue decoder value = case value of @@ -45,3 +46,11 @@ decodeHttpValue decoder value = Err msg -> fail (UnexpectedPayload msg) _ -> fail (UnexpectedPayload "Response body is a blob, expecting a string.") + +errorKey : Error -> String +errorKey error = + case error of + Timeout -> "Timeout" + NetworkError -> "NetworkError" + UnexpectedPayload _ -> "UnexpectedPayload" + BadResponse _ key -> key |