elm / http

Make HTTP requests in Elm
https://package.elm-lang.org/packages/elm/http/latest
BSD 3-Clause "New" or "Revised" License
154 stars 46 forks source link

Add examples for handling BadStatus Http.Error with Response Body #59

Open AntonLebiodkin opened 5 years ago

AntonLebiodkin commented 5 years ago

Hi, folks! We have our Elm app where the server sends to us some objects with validation errors in them with BadStatus. Previously we handled response body from BadStatus Http.Error. But after contract change in elm/http (previously evancz/elm-http), we can't figure out how to get it correctly.

P.S. We're using Http.task, so seems we can't add there expect field to get additional info, cause it exists only on Http.request

alex-tan commented 5 years ago

@AntonLebiodkin there's some explanation here. You can replace Http.Error with your own custom error type and in the BadStatus case attempt to run a decoder on the body to get the validation errors.

jjagielka commented 4 years ago

There's no issue of creating your own version of Http.Error and extend the handling of missing 400 - body responses. The problem is with usage of third party packages like RemoteData. Those packages import Http.Error directly and are not aware about the custom handlers you've created. This force you to copy paste a lot of type declarations.