-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get error text with elm 0.19? #28
Comments
It will be up to the developer to create a custom |
Seems like a good place for a package :) |
Something like: module Http.Extra exposing (errorToString)
import Http exposing (Error(..))
import Json.Decode as Json
parseError : String -> Maybe String
parseError =
Json.decodeString (Json.field "error" Json.string) >> Result.toMaybe
errorToString : Http.Error -> String
errorToString err =
case err of
Timeout ->
"Timeout exceeded"
NetworkError ->
"Network error"
BadStatus resp ->
parseError resp.body
|> Maybe.withDefault (String.fromInt resp.status.code ++ " " ++ resp.status.message)
BadPayload text resp ->
"Unexpected response from api: " ++ text
BadUrl url ->
"Malformed url: " ++ url |
With And the docs contain a similar example |
Hi
The documentation still contains:
However toString is not available any more in elm 0.19. It was replaced with Debug.toString, String.fromInt and String.fromFloat. Debug.toString is not available outside of debug mode.
So how can I get the error now?
The text was updated successfully, but these errors were encountered: