An experimental alternative for elm/http.
Warning: Not battle tested yet. Use with care.
put patch and delete.Cmd to Task gradually (and vice versa).Http.Error to custom error gradually.Create a task that can return Http.Error.
getRepoCompatible : String -> String -> Task Http.Error Repo
getRepoCompatible userName repoName =
Req.get ("https://api.github.com/repos/" ++ userName ++ "/" ++ repoName)
|> Req.jsonCompatible repoDecoderCreate a task that can return Req.Error which contains the full information.
getRepo : String -> String -> Task (Req.Error String) Repo
getRepo userName repoName =
Req.get ("https://api.github.com/repos/" ++ userName ++ "/" ++ repoName)
|> Req.json repoDecodertype alias Error a =
{ request : Req
, error : Problem a
}
type Problem a
= BadUrl String
| Timeout
| NetworkError
| BadStatus Http.Metadata a
| BadBody Http.Metadata StringYou can also decode error body using *WithError family.
getRepo : String -> String -> Task (Req.Error ErrorInfo) Repo
getRepo userName repoName =
Req.get ("https://api.github.com/repos/" ++ userName ++ "/" ++ repoName)
|> Req.jsonWithError
{ decoder = repoDecoder, errorDecoder = errorDecoder }
errorDecoder : Http.Metadata -> Decoder ErrorInfo
errorDecoder meta =
D.map ErrorInfo
(D.field "message" D.string)