Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
Add json response exceptions_app (#675)
Browse files Browse the repository at this point in the history
* Add json response exceptions_app

* run rubocop
  • Loading branch information
FinnIckler authored Sep 9, 2024
1 parent 3f7c7e8 commit 957dea5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class ErrorsController < ApplicationController
def show
exception = request.env['action_dispatch.exception']
status_code = ActionDispatch::ExceptionWrapper.new(request.env, exception).status_code
request_id = request.env['action_dispatch.request_id']
render json: { error: ErrorCodes::INTERNAL_SERVER_ERROR, request_id: request_id }, status: status_code
end
end
5 changes: 5 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

# Returns json on error
config.exceptions_app = ->(env) {
ErrorsController.action(:show).call(env)
}
end
1 change: 1 addition & 0 deletions lib/error_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module ErrorCodes
INVALID_TOKEN = -1
EXPIRED_TOKEN = -2
MISSING_AUTHENTICATION = -3
INTERNAL_SERVER_ERROR = -4

# Competition Errors
COMPETITION_NOT_FOUND = -1000
Expand Down

0 comments on commit 957dea5

Please sign in to comment.