From efa8c6cca488b8f8b6a5a0d51a3389936d91ebff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Pen=CC=83a=20Pita?= Date: Tue, 29 Sep 2020 00:17:06 +0200 Subject: [PATCH] Use verify_request_format! method to check valid request format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- app/controllers/exception_handler/exceptions_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/exception_handler/exceptions_controller.rb b/app/controllers/exception_handler/exceptions_controller.rb index 4f2f2389..bd62ba26 100644 --- a/app/controllers/exception_handler/exceptions_controller.rb +++ b/app/controllers/exception_handler/exceptions_controller.rb @@ -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