Skip to content

Instantly share code, notes, and snippets.

@ababup1192
Last active July 30, 2019 20:49
Show Gist options
  • Save ababup1192/89c0d1e4a67d45004690f6f7f9209931 to your computer and use it in GitHub Desktop.
Save ababup1192/89c0d1e4a67d45004690f6f7f9209931 to your computer and use it in GitHub Desktop.
jsonResolver : D.Decoder a -> Http.Resolver Http.Error a
jsonResolver decoder =
Http.stringResolver <|
\response ->
case response of
Http.BadUrl_ url ->
Err (Http.BadUrl url)
Http.Timeout_ ->
Err Http.Timeout
Http.NetworkError_ ->
Err Http.NetworkError
Http.BadStatus_ metadata body ->
Err (Http.BadStatus metadata.statusCode)
Http.GoodStatus_ metadata body ->
case D.decodeString decoder body of
Ok value ->
Ok value
Err err ->
Err (Http.BadBody (D.errorToString err))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment