mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Respond to all formats with html
This commit is contained in:
@@ -9,7 +9,7 @@ class ErrorsController < ApplicationController
|
||||
|
||||
event.add_metadata(:request, request.env)
|
||||
end
|
||||
render status: :not_found
|
||||
render "not_found", status: :not_found, formats: :html
|
||||
end
|
||||
|
||||
def internal_server_error
|
||||
|
||||
21
spec/requests/errors_spec.rb
Normal file
21
spec/requests/errors_spec.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe 'Errors', type: :request do
|
||||
include ExceptionHelper
|
||||
|
||||
shared_examples "returning a HTTP 404" do |path|
|
||||
it path do
|
||||
rails_respond_without_detailed_exceptions do
|
||||
get path
|
||||
end
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like "returning a HTTP 404", "/nonexistent/path"
|
||||
it_behaves_like "returning a HTTP 404", "/nonexistent/path.jpg"
|
||||
it_behaves_like "returning a HTTP 404", "/nonexistent/path.xml"
|
||||
end
|
||||
16
spec/support/request/exception_helper.rb
Normal file
16
spec/support/request/exception_helper.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# https://medium.com/@edgar/rspec-how-to-have-rails-request-specs-handling-errors-like-production-a8c21ed0308a
|
||||
module ExceptionHelper
|
||||
def rails_respond_without_detailed_exceptions
|
||||
env_config = Rails.application.env_config
|
||||
original_show_exceptions = env_config['action_dispatch.show_exceptions']
|
||||
original_show_detailed_exceptions = env_config['action_dispatch.show_detailed_exceptions']
|
||||
env_config['action_dispatch.show_exceptions'] = true
|
||||
env_config['action_dispatch.show_detailed_exceptions'] = false
|
||||
yield
|
||||
ensure
|
||||
env_config['action_dispatch.show_exceptions'] = original_show_exceptions
|
||||
env_config['action_dispatch.show_detailed_exceptions'] = original_show_detailed_exceptions
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user