jeudi 14 juillet 2016

using a generic error handler after `render` has been called

I'm working on a Rails 3 API project and am running into an AbstractController::DoubleRenderError, which I would like to avoid.

There is a filter that is executing on both sides of a controller action that is raising an unexpected exception after the controller action has completed. Because the controller action has completed, render has already been called. A rescue_from handler that is configured in the controller base class then kicks in and attempts to render a generic JSON error message, but since the controller action has already called render the AbstractController::DoubleRenderError is raised.

Is there a way in Rails 3 to avoid assuming that a controller action render is the last nontrivial user code that will be executed so that errors can be gracefully handled after any action render calls?

Aucun commentaire:

Enregistrer un commentaire