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

Add json response exceptions_app #675

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading