rowtype-yoga / purescript-fetch

MIT License
25 stars 2 forks source link

Handle running `json` on responses without body more gracefully #7

Closed i-am-the-slime closed 1 year ago

i-am-the-slime commented 1 year ago

If you attempt to do run json on a response without a body you get an ugly messageless error right now. I think json could either return a Maybe or we could default to {}.

sigma-andex commented 1 year ago

Wouldn't it be better to throw the error in Aff? Than you can attempt it if needed. I think usually you expect a proper message or it should be encoded in the http status, like e.g. 204. Everything else is imho an error on the backend side. Maybe would also be very annoying most of the times and returning {} in the empty case just feels wrong imho.

i-am-the-slime commented 1 year ago

Yeah, I am doing attempt but of course only after I get a production crash and find out that I should've used attempt because this specific error code does not have a body. I guess another alternative is to just read the body as a string and parse it on the PureScript side.