Hello,
A simple question about the elm-lang/http 1.0.0 module.
How could Response String use in the BadPayload type definition while it refers to Response body i.e. a record ? What is the purpose or the goal of that?
type Error
= BadPayload String (Response String)
type alias Response body = { url : String ,
status : { code : Int, message : String } ,
headers : Dict String String ,
body : body }
It’s been well explained in this good article that Response String is actually a record! So why not use Reponse body directly?! There should be a good reason!
In that definition type alias Response body = ..., body is itself a type variable, same as if you said type alias Response a = ..., so when it defines BadPayload with Response String, it is just saying that the body will be a String rather than some other type.
Or should I consider Response String as a constructor having a string (the server response) as its argument and returning the record?
That sounds good to me.
Response is a type alias for a record representing the response, with the types of the body field of the response parametrized. In other words, Response theTypeOfBody is a convenient name for the shape of any record with this shape:
When you’re dealing with a BadPayload error, this means that the body does not match what was expected. Most often, this means that a JSON decoder failed to decode it. In that case, having the Response record with the body as a plain String means you can log the exact string-value that your decoder failed to decode.