Rails render html not json when an exception is thrown

I hope someone can help with this problem.

I have a web services application that I am writing in rails. I am using RocketPants for services and Authority for authorization.

I'm having an exception handling issue where the "now resolvable" permission exception (Authority :: SecurityViolation) is rendered as HTML instead of JSON.

I have documented the story in this sense and this question .

I can replicate by throwing an exception in my ApiController for example raise "blah"

and get an html error page. I tried using rescue_from

as in this question with the same unfortunate result.

I don't know where from here. Does anyone know of anything on the Rails exception handling stack that causes this? I would appreciate any help.

+3


source to share


1 answer


Have you tried this in your ApiController class?



rescue_from StandardError, with: :render_unknown_error


def render_unknown_error(error)
  render(json: error.inspect, status: 500)
end

      

+2


source







All Articles