diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb index b3619b70..df88afde 100644 --- a/app/controllers/errors_controller.rb +++ b/app/controllers/errors_controller.rb @@ -15,6 +15,11 @@ class ErrorsController < ActionController::Base '/api/templates/docx' ].freeze + SAFE_ERROR_MESSAGE_CLASSES = [ + ActionDispatch::Http::Parameters::ParseError, + JSON::ParserError + ].freeze + def show if request.original_fullpath.in?(ENTERPRISE_PATHS) && error_status_code == 404 return render json: { status: 404, message: ENTERPRISE_FEATURE_MESSAGE }, status: :not_found @@ -24,7 +29,11 @@ class ErrorsController < ActionController::Base f.json do set_cors_headers - render json: { status: error_status_code }, status: error_status_code + exception = request.env['action_dispatch.exception'] + + error = exception.message if exception.class.in?(SAFE_ERROR_MESSAGE_CLASSES) + + render json: { status: error_status_code, error: }.compact, status: error_status_code end f.html { render error_status_code.to_s, status: error_status_code } diff --git a/config/environments/production.rb b/config/environments/production.rb index e85a1d91..9f45fc42 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -128,7 +128,12 @@ Rails.application.configure do config.lograge.formatter = ->(data) { data.except(:path, :location).to_json } config.lograge.custom_payload do |controller| - params = controller.request.try(:params) || {} + params = + begin + controller.request.try(:params) || {} + rescue StandardError + {} + end { fwd: controller.request.ip,