diff options
author | Joris | 2016-01-04 00:34:48 +0100 |
---|---|---|
committer | Joris | 2016-01-04 00:40:25 +0100 |
commit | 6b090b3bdef7108d51d93207e28b148c121767aa (patch) | |
tree | f0815d638723b62b5f16cf9d94ce5783751fc3db /src/client/elm/SimpleHTTP.elm | |
parent | d9df5c3fcffe12aac239b58ccf2fd82c19c3be62 (diff) |
Simplify server communicaitons in client
Diffstat (limited to 'src/client/elm/SimpleHTTP.elm')
-rw-r--r-- | src/client/elm/SimpleHTTP.elm | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/src/client/elm/SimpleHTTP.elm b/src/client/elm/SimpleHTTP.elm deleted file mode 100644 index 3e01178..0000000 --- a/src/client/elm/SimpleHTTP.elm +++ /dev/null @@ -1,47 +0,0 @@ -module SimpleHTTP - ( post - , decodeHttpValue - ) where - -import Http exposing (..) -import Task exposing (..) -import Json.Decode as Json exposing (Decoder) - -post : String -> Task Error Value -post url = - { verb = "POST" - , headers = [] - , url = url - , body = empty - } - |> Http.send defaultSettings - |> mapError promoteError - |> flip Task.andThen handleResponse - -handleResponse : Response -> Task Error Value -handleResponse response = - if 200 <= response.status && response.status < 300 - then Task.succeed response.value - else fail (BadResponse response.status (responseString response.value)) - -responseString : Value -> String -responseString value = - case value of - 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 - Text str -> - case Json.decodeString decoder str of - Ok v -> succeed v - Err msg -> fail (UnexpectedPayload msg) - _ -> - fail (UnexpectedPayload "Response body is a blob, expecting a string.") |