Skip to content

Commit

Permalink
Make rails app available to catch RoutingError (raised by ActionDispa…
Browse files Browse the repository at this point in the history
…tch)

Ref: rails/rails#671
  • Loading branch information
sfate committed Feb 17, 2017
1 parent d5f7492 commit 89c8e57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/concerns/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ module Errors
rescue_from ActionController::RoutingError, with: -> { render_error(code: 404) }
end

# NOTE: Alexey Bobyrev 14 Jan 2017
# Raise error here to make it visible for application#rescue_from
# Ref: https://github.com/rails/rails/issues/671
def raise_routing_error
raise ActionController::RoutingError.new(params[:path])
end

protected

def render_error(code:)
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -626,4 +626,7 @@
mount WeddingAtelier::Engine, at: '/wedding-atelier'

match '*path', to: 'errors/invalid_format#capture_php', constraints: lambda { |request| request.path[/\.php$/] }
# NOTE: Alexey Bobyrev 14 Jan 2017
# Any other routes are handled here (as ActionDispatch prevents RoutingError from hitting ApplicationController::rescue_action)
match '*path', to: 'application#raise_routing_error'
end

0 comments on commit 89c8e57

Please sign in to comment.