Skip to content

Instantly share code, notes, and snippets.

@jzxhuang
Last active April 4, 2019 07:45
Show Gist options
  • Save jzxhuang/6470a74ecef6b5e5a7f05c431128bc62 to your computer and use it in GitHub Desktop.
Save jzxhuang/6470a74ecef6b5e5a7f05c431128bc62 to your computer and use it in GitHub Desktop.
An expectString function with a more detailed successful response and error.
-- Change this to return Result ErrorDetailed ( Http.Metadata, String ) instead of Result Http.Error ( Http.Metadata, String )
convertResponseString : Response String -> Result ErrorDetailed ( Metadata, String )
convertResponseString httpResponse =
case httpResponse of
Http.BadUrl_ url ->
Err (BadUrl url)
Http.Timeout_ ->
Err Timeout
Http.NetworkError_ ->
Err NetworkError
Http.BadStatus_ metadata body ->
Err (BadStatus metadata body)
Http.GoodStatus_ metadata body ->
Ok ( metadata, body )
-- Update this function's type signature accordingly
expectStringDetailed : (Result ErrorDetailed ( Metadata, String ) -> msg) -> Expect msg
expectStringDetailed msg =
Http.expectStringResponse msg convertResponseString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment