I am using RABL for my REST API. However, currently, even if there is an error, the HTTP response code I get is 200. Is there a way to change this to a 4xx level code? It would be great for my client to read.
I am not using the render template: "api/v1/error.rabl”
because if I do use it, there is an after filter that sets CORS access control headers which does not get executed.
I tried searching, but didn’t find a way.
Seems like this answer provides a good solution. For example,
Although the wiki has a warning that "setting
controller.response.status
is like a default value",respond_with
orrender
shouldn't explicitly setstatus
and it seems like a call torender "my_template"
triggers that200
you mentioned. If you do want to reuse a single error template, something like the author's suggested template, this works:This works with actions that write as well as read. The original bug discussion also has some interesting examples.