summaryrefslogtreecommitdiff
path: root/lib/api.rb
diff options
context:
space:
mode:
authorFelix Gilcher <felix.gilcher@asquera.de>2013-02-01 09:42:02 +0000
committerFelix Gilcher <felix.gilcher@asquera.de>2013-02-01 10:23:23 +0000
commitc72910a8bf782c10662dd4392e81ef6408f801ee (patch)
treefebf03f0536749d6abd935a93632a984ae3bc8f2 /lib/api.rb
parent2a669fc89997376af1e76bf3ed574d948009c5b2 (diff)
downloadgitlab-ce-c72910a8bf782c10662dd4392e81ef6408f801ee.tar.gz
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.
Diffstat (limited to 'lib/api.rb')
-rw-r--r--lib/api.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/api.rb b/lib/api.rb
index 3dd827158db..15d99cc767b 100644
--- a/lib/api.rb
+++ b/lib/api.rb
@@ -8,7 +8,16 @@ module Gitlab
rack_response({'message' => '404 Not found'}.to_json, 404)
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)
end