elm / http

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

Handling custom errors in 2.0.0 #51

Closed nabilspottt closed 5 years ago

nabilspottt commented 5 years ago

Hello there,

At my job, we are experiencing some difficulties switching to v2.0.0 as we are trying to provide our requests different return messages according to the http status of the response. Because now the Http.Error BadStatus only provides the http code, we cannot get further data from the response. We are trying to pattern-match the http status and catch the response directly with the function expectStringResponse but it seems a bit complicated.

So why not directly exposing the response through BadStatus anymore ? And do some of you have examples of how to easily handle custom errors through the new API ?

Thanks for reading, please forgive my english :)

evancz commented 5 years ago

I think the expectStringResponse function will help you.

It gives you full access to the Response and Metadata, so you can do whatever you want with it.

For further questions, I recommend asking on https://discourse.elm-lang.org/ or https://elmlang.herokuapp.com/ where there are a bunch more folks who would have an easier time replying!

sporto commented 5 years ago

We have the same issue.

In v2 error information was removed from BadStatus. Having a status only is not enough for logging and auditing error. For example it is usual to return 422 errors when you receive a bad input from the front end, with details about the error in the body.

Please consider adding this information back to Error.

Also some libraries like elm-graphql wrap Error. They have lost valuable error information in the upgrade.