Commit c72910a8bf782c10662dd4392e81ef6408f801ee
1 parent
2a669fc8
Exists in
master
and in
4 other branches
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.
Showing
2 changed files
with
11 additions
and
1 deletions
Show diff stats
config/routes.rb
lib/api.rb
... | ... | @@ -8,7 +8,16 @@ module Gitlab |
8 | 8 | rack_response({'message' => '404 Not found'}.to_json, 404) |
9 | 9 | end |
10 | 10 | |
11 | - rescue_from :all do | |
11 | + rescue_from :all do |exception| | |
12 | + # lifted from https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L60 | |
13 | + # why is this not wrapped in something reusable? | |
14 | + trace = exception.backtrace | |
15 | + | |
16 | + message = "\n#{exception.class} (#{exception.message}):\n" | |
17 | + message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code) | |
18 | + message << " " << trace.join("\n ") | |
19 | + | |
20 | + API.logger.add Logger::FATAL, message | |
12 | 21 | rack_response({'message' => '500 Internal Server Error'}, 500) |
13 | 22 | end |
14 | 23 | ... | ... |