An experimental alternative for elm/http.
Warning: Not battle tested yet. Use with care.
Note: If you use --debug, you'll need two extra dependency, elm/file and elm/bytes.
This is a workaround for a known Map.! bug. Move those into "direct" by running elm install.
elm install elm/file
elm install elm/bytesFor more details, See this issue or this repo.
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
, problem : 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)