I am using Sinatra to develop this JSON API. As I developed it, error messages are also sent to JSON in a specific format. The only difference is that they will have a status code of 4xx instead of 2xx or 3xx. Now the problems that I encountered:
I defined a general filter in which I set the content type of the response. Like this:
before { content_type :json }
problem, every time I call halt, this parameter is not taken into account. I have to configure it to stop the call in a very ugly, more verbose and error prone way:
halt [404, {"Content-Type" => "application/json;charset=utf-8"}]
is there any other way to do this?
The problem that is phasing me the most: when I stop with the 404 code after I catch the 404 error (see below), the JSON content type and json body are strange, I don't get any body, neither browser nor curl. How so?
error 404 do halt [404...{"bang" => "bong"....}] end
UPDATE
Regarding the last issue, here's what happens using curl and making a call that will fall into 404 error block:
curl http://faulty_url
perhaps this helps.
source share