From 7ad18e73ce5981e6409b36b7cd7681a6d5881955 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Fri, 13 Nov 2020 15:53:11 +0100 Subject: [PATCH] Log errors into standard out We want better error visibility. --- .../alchemy/json_api/base_controller.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/controllers/alchemy/json_api/base_controller.rb b/app/controllers/alchemy/json_api/base_controller.rb index c89399a..13d0535 100644 --- a/app/controllers/alchemy/json_api/base_controller.rb +++ b/app/controllers/alchemy/json_api/base_controller.rb @@ -7,6 +7,23 @@ class BaseController < ::ApplicationController include JSONAPI::Errors include JSONAPI::Filtering include JSONAPI::Pagination + + private + + def render_jsonapi_internal_server_error(exception) + log_error(exception) + super + end + + def log_error(exception) + logger = Rails.logger + return unless logger + + message = +"\n#{exception.class} (#{exception.message}):\n" + message << exception.annotated_source_code.to_s if exception.respond_to?(:annotated_source_code) + message << " " << exception.backtrace.join("\n ") + logger.fatal("#{message}\n\n") + end end end end