purescript-contrib/purescript-affjax

Throws error if response body is empty

Closed this issue · 2 comments

It appears that affjax throws an error when the response body is empty or not valid json for some reason.

I am serving my API with servant, and fetch a resource with, for example, Affjax.get "/api/order/123".

My observations so far:

throwError err404 -- Unexpected end of input (JSON error)
throwError $ err404 { errBody = "foobar" } -- Unexpected token f at position 0
throwError $ err404 { errBody = "{}" } -- Works fine

I am yet to dive into the affjax codebase, so cannot offer a fix right now, so I am just leaving this one here for now.

garyb commented

This is a duplicate of #34 pretty much, but #102 (wip #107, will probably change to use web-xhr too though) will fix this. Part of the solution is it will remove JSON (and all non-primitive) things as being expected responses, so it will be up leaving the caller to deal with response parsing instead.

I just got bit by this as well. It was very unclear at first what was going on. Glad it's being worked on.