Rails multiple exceptions handler with "exceptions_app" per route namespace

Viewed 547

is there any solution how to handle Rails exceptions per route namespace with defined direction config.exceptions_app ?

I have versioned interface eg /api/v1, /api/v2. Every namespace uses different JSON/XML/HTML response structure.

Global definition is nice, but i need something more dynamic.

RESOLVE:

config.exceptions_app takes closure/lambda block. In that block i could create simple case statement like this:

config.exceptions_app = lambda do |env|
  case env['REQUEST_PATH']
  when %r{^(\/api\/v1)}
    Api::V1::ExceptionsController.action(:show).call(env)
  when %r{^(\/api\/v2)}
    Api::V2::ExceptionsController.action(:show).call(env)
  when %r{^(\/cms\/)}
    Cms::ExceptionsController.action(:show).call(env)
  end
end
2 Answers
Related