Skip to content
Snippets Groups Projects
Commit c72910a8 authored by Felix Gilcher's avatar Felix Gilcher
Browse files

log fatal errors that we catch

In case we rescue from a fatal error, we want the error and the backtrace to
the error logged, so we can debug later on. This change injects the configured
logger from the rails app to the grape API and logs error as well as backtrace
in a rails-like fashion.
parent 2a669fc8
No related branches found
No related tags found
No related merge requests found
Loading
@@ -8,6 +8,7 @@ Gitlab::Application.routes.draw do
Loading
@@ -8,6 +8,7 @@ Gitlab::Application.routes.draw do
   
# API # API
require 'api' require 'api'
Gitlab::API.logger Rails.logger
mount Gitlab::API => '/api' mount Gitlab::API => '/api'
   
constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? } constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? }
Loading
Loading
Loading
@@ -8,7 +8,16 @@ module Gitlab
Loading
@@ -8,7 +8,16 @@ module Gitlab
rack_response({'message' => '404 Not found'}.to_json, 404) rack_response({'message' => '404 Not found'}.to_json, 404)
end end
   
rescue_from :all do rescue_from :all do |exception|
# lifted from https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L60
# why is this not wrapped in something reusable?
trace = exception.backtrace
message = "\n#{exception.class} (#{exception.message}):\n"
message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
message << " " << trace.join("\n ")
API.logger.add Logger::FATAL, message
rack_response({'message' => '500 Internal Server Error'}, 500) rack_response({'message' => '500 Internal Server Error'}, 500)
end end
   
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment