From 7670578784f2d7f8c671255c58679b9dfab75c0b Mon Sep 17 00:00:00 2001 From: Wendel Fabian Chinsamy Date: Wed, 22 May 2024 16:48:00 +0200 Subject: [PATCH] report on errors that occur in the rack middleware --- config/environments/development.rb | 2 +- config/environments/test.rb | 2 +- lib/middleware/compressed_requests.rb | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 86f13ae..b1e79eb 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -60,7 +60,7 @@ use_timestamp: false, } - config.action_dispatch.show_exceptions = false + config.action_dispatch.show_exceptions = :none end #BetterErrors::Middleware.allow_ip! ENV['TRUSTED_IP'] diff --git a/config/environments/test.rb b/config/environments/test.rb index 0620141..041afa5 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -28,7 +28,7 @@ # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = false + config.action_dispatch.show_exceptions = :none # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false diff --git a/lib/middleware/compressed_requests.rb b/lib/middleware/compressed_requests.rb index 13d1493..0473fcb 100644 --- a/lib/middleware/compressed_requests.rb +++ b/lib/middleware/compressed_requests.rb @@ -29,8 +29,13 @@ def call(env) env['rack.input'] = StringIO.new(extracted) end - status, headers, response = @app.call(env) - [status, headers, response] + begin + status, headers, response = @app.call(env) + [status, headers, response] + rescue => err + Rails.logger.error(err.inspect) + [500, {}, [{"status": 500, "title": err.message}.to_json]] + end end def decode(input, content_encoding)