What's the best way to handle an empty (no string at all) response?
Although the response code is 200, Elm returns an error because an empty response is not a valid JSON.
Here is my current code:
decodeAlwaysTrue : Json.Decode.Decoder Bool
decodeAlwaysTrue =
Json.Decode.succeed True
Http.send Http.defaultSettings httpConfig
|> Http.fromJson decodeAlwaysTrue
|> Task.perform FetchFail DeleteUserSuccess
EDIT1:
This a POST action so I can't use getString.
You could use the getString
function from the Http
module. That will give you back whatever string is returned from the HTTP request without attempting to convert is to a Json value.
If you instead need to use Http.send
then you could do something like this:
Http.send Http.defaultSettings httpConfig
|> Task.perform FetchFail (always DeleteUserSuccess)
This assumes that DeleteUserSuccess
is changed to be defined with no type parameter:
type Msg =
...
DeleteUserSuccess
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With