Skip to content

Commit

Permalink
Use verify_request_format! method to check valid request format
Browse files Browse the repository at this point in the history
This commit fix a problem to be able to render error responses for 
format distinct to html (for example json) because e.request.format is
returning a Mime::Type object that doesn’t match with the values in 
self.class.respond_to that is a hash with keys :html, :json, etc

Using the responders’ verify_requested_format! we are getting exactly
the same goal delegating the tasks in the own responders gem.
  • Loading branch information
Felipe Peña Pita committed Sep 28, 2020
1 parent 861a651 commit efa8c6c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/controllers/exception_handler/exceptions_controller.rb
Expand Up @@ -22,7 +22,11 @@ class ExceptionsController < ApplicationController

# => Response format (required for non-standard formats (.css / .gz etc))
# => request.format required until responders updates with wildcard / failsafe (:all)
before_action { |e| e.request.format = :html unless self.class.respond_to.include? e.request.format }
before_action do |e|
verify_requested_format!
rescue
e.request.format = :html
end

# => Routes
# => Removes need for "main_app" prefix in routes
Expand Down

0 comments on commit efa8c6c

Please sign in to comment.