Skip to content

Commit

Permalink
render errors as json for api requests
Browse files Browse the repository at this point in the history
  • Loading branch information
FinnIckler committed Aug 29, 2024
1 parent fcb973b commit ca5b6d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions app/controllers/api_errors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class ApiErrorsController < ApplicationController
skip_before_action :set_locale
skip_before_action :store_user_location!
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_code: status_code, request_id: request_id, contact_url: Rails.application.routes.url_helpers.contact_url(contactRecipient: 'wst', requestId: request_id)}, status: status_code
end
end
6 changes: 5 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@

# Error pages for production
config.exceptions_app = ->(env) {
ErrorsController.action(:show).call(env)
if EnvConfig.API_ONLY?
ApiErrorsController.action(:show).call(env)
else
ErrorsController.action(:show).call(env)
end
}

# Only loads a smaller set of middleware suitable for API only apps.
Expand Down
2 changes: 1 addition & 1 deletion infra/wca_on_rails/staging/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ resource "aws_ecs_task_definition" "this" {

# This is shared with the API Server
cpu = "1536"
memory = "7861"
memory = "5813"

container_definitions = jsonencode([
{
Expand Down

0 comments on commit ca5b6d8

Please sign in to comment.