What happens if a Http.get request in Elm receives a different type of response other than expected one?

user6435535

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?

glennsl

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

What happens in HTTP response to a GET request without Content-Length or Transfer-encoding?

How to make http request and decode response to concrete type in Elm 0.17?

What happens when a browser that supports SPDY receives an HTTP2 (H2) response?

HTTP Response content type different on HEAD request

What happens when a HTTP request uses different browser headers?

Is it possible to specify more than one expected-response-type?

Component makes a GET request on mounted() and props response to child component. What happens if I type URL that goes straight to child component?

What happens to a killed HTTP request?

Chain http request and merge json response in ELM

Is cookie part of the header of a http request/response? Is it a key value pair? How different is it than Accept or Content-type header keys?

Angular 12 how to return an http get request array of objects and assign to other array of different type using map()

What happens when a service receives a request but has no ready pods?

What happens if a second HTTP request is made before I receive the response of the first request?

Angular - get response from more than one request

What happens for a smart HTTP request for a git pack file when a repository has more than 4 billion objects?

HTTP Request Response in Different Flow

How to write a test for an http get request in elm

What I do to one button happens to the other

API for receiving JSON via POST receives a different type than sent

how to get response of http request

One http request with two http response in Chrome

What is the http request and response body for this URL request?

Could not get a expected Response through a POST request

HTTP Get request from Angular JS receives empty reply

redirect to method if post type method receives get request

Elm: How to use data from one HTTP request in subsequent requests

Elm Http Request on Init

How to set a custom content type in an Elm HTTP request

What happens when a Task is run but finishes after the HTTP response is returned?