1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-19 02:27:03 +00:00
Files
go-inbucket/ui/src/HttpUtil.elm
2018-11-17 18:48:52 -08:00

49 lines
1.1 KiB
Elm

module HttpUtil exposing (delete, errorString, patch)
import Http
delete : (Result Http.Error () -> msg) -> String -> Cmd msg
delete msg url =
Http.request
{ method = "DELETE"
, headers = []
, url = url
, body = Http.emptyBody
, expect = Http.expectWhatever msg
, timeout = Nothing
, tracker = Nothing
}
patch : (Result Http.Error () -> msg) -> String -> Http.Body -> Cmd msg
patch msg url body =
Http.request
{ method = "PATCH"
, headers = []
, url = url
, body = body
, expect = Http.expectWhatever msg
, timeout = Nothing
, tracker = Nothing
}
errorString : Http.Error -> String
errorString error =
case error of
Http.BadUrl str ->
"Bad URL: " ++ str
Http.Timeout ->
"HTTP timeout"
Http.NetworkError ->
"HTTP Network error"
Http.BadStatus res ->
"Bad HTTP status: " ++ String.fromInt res
Http.BadBody msg ->
"Bad HTTP body: " ++ msg