From 9d57e149fcb124a28813c56f83cf254eb92baa42 Mon Sep 17 00:00:00 2001 From: Joris Date: Fri, 11 Mar 2016 23:21:06 +0100 Subject: Don't use persona anymore, use email token to sign in --- src/client/elm/Utils/Http.elm | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/client/elm/Utils') 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 -- cgit v1.2.3