Skip to content

Commit

Permalink
Merge pull request #186 from datacite/fix-500-errors
Browse files Browse the repository at this point in the history
report on errors that occur in the rack middleware
  • Loading branch information
wendelfabianchinsamy authored May 22, 2024
2 parents 07b92c1 + 7670578 commit 1ba7f9a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions lib/middleware/compressed_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1ba7f9a

Please sign in to comment.