diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 88781029..4b974750 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,16 +1,7 @@ class ApplicationController < ActionController::Base - rescue_from Exception, with: :show_error + rescue_from ActionController::UnknownFormat, with: :handle_unknown_format - def show_error(e) - Rails.logger.error(e) - - raise if !request.xhr? || !Rails.env.development? - - if Rails.env.development? - render json: { message: e.message, log: e.backtrace.join("\n") }, - status: :unprocessable_entity - else - render json: { message: e.message }, status: :unprocessable_entity - end + def handle_unknown_format + render nothing: true, status: 406 end end diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 4704340c..e9f4b657 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -2,7 +2,7 @@ class MainController < ApplicationController before_action :redirect_to_https, only: ['home'] def home - render(json: request.env.inspect) && return if params[:debug] + respond_to :html end def status diff --git a/spec/controllers/unknown_format_spec.rb b/spec/controllers/unknown_format_spec.rb new file mode 100644 index 00000000..79483dcc --- /dev/null +++ b/spec/controllers/unknown_format_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +feature 'Unexpected request formats' do + controller do + def index + respond_to do |format| + format.html { render nothing: true } + end + end + end + + scenario 'accepted content-type matches exceptations' do + get :index + + response.should be_success + end + + scenario 'content-type format does not match expectations' do + get :index, format: :json + + response.status.should eq 406 + end +end