[30092] Use delegated logger (sentry) for logged API errors

pull/7261/head
Oliver Günther 6 years ago
parent c726126868
commit f487fcacca
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 4
      lib/api/root.rb
  2. 11
      lib/api/utilities/grape_helper.rb
  3. 4
      lib/open_project/logging/log_delegator.rb

@ -220,8 +220,8 @@ module API
e.error_response status: 401, message: representer.to_json, headers: warden.headers, log: false
end
error_response ActiveRecord::RecordNotFound, ::API::Errors::NotFound
error_response ActiveRecord::StaleObjectError, ::API::Errors::Conflict
error_response ActiveRecord::RecordNotFound, ::API::Errors::NotFound, log: false
error_response ActiveRecord::StaleObjectError, ::API::Errors::Conflict, log: false
error_response MultiJson::ParseError, ::API::Errors::ParseError

@ -66,6 +66,7 @@ module API
def default_error_response(headers, log)
lambda { |e|
original_exception = $!
representer = ::API::V3::Errors::ErrorRepresenter.new e
resp_headers = instance_exec &headers
env['api.format'] = 'hal+json'
@ -74,16 +75,20 @@ module API
message = <<-MESSAGE
Grape rescuing from error: #{e}
Original error: #{$!.inspect}
Original error: #{original_exception.inspect}
Stacktrace:
MESSAGE
$@.each do |line|
OpenProject.logger.clean_backtrace(original_exception).each do |line|
message << "\n #{line}"
end
Rails.logger.error message
OpenProject.logger.error(
message,
exception: original_exception,
reference: :APIv3
)
end
error_response status: e.code, message: representer.to_json, headers: resp_headers

@ -26,9 +26,13 @@ module OpenProject
registered_handlers.values.each do |handler|
handler.call message, context
rescue StandardError => e
Rails.logger.error "Failed to delegate log to #{handler.inspect}: #{e.inspect}"
end
nil
rescue StandardError => e
Rails.logger.error "Failed to process log message #{exception.inspect}: #{e.inspect}"
end
%i(debug info warn error fatal unknown).each do |level|

Loading…
Cancel
Save