1
votes

In Elm tutorial, Http section, there is code sample where defines the Cmd for run-time to handle:

Http.get
      { url = "https://elm-lang.org/assets/public-opinion.txt"
      , expect = Http.expectString GotText
      }

So we expect server response to be text and pass the message type (GotText) to Http.expectString function so later the result would be attached to GotText. Here is GotText definition (it is of type: Result):

type Msg
  = GotText (Result Http.Error String)

So if any error happens during request, plus the expected response type, it would be captured inside Http.Error attached to GotText, otherwise a run-time error happens (which is not true in ELm). My question is what if server returns something other that text, i.e. binary? AFAIK there doesn't exist such a Http error as bad response, so is that type of error still embedded inside Http.Error in ELm?

1

1 Answers

5
votes

But there is. From the elm/http docs on Http.Error:

BadBody means you got a response back with a nice status code, but the body of the response was something unexpected. The String in this case is a debugging message that explains what went wrong with your JSON decoder or whatever.