Module: Oboe::Grape::Middleware::Error

Defined in:
lib/oboe/frameworks/grape.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



49
50
51
# File 'lib/oboe/frameworks/grape.rb', line 49

def self.included(klass)
  ::Oboe::Util.method_alias(klass, :error_response, ::Grape::Middleware::Error)
end

Instance Method Details

#error_response_with_oboe(error = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/oboe/frameworks/grape.rb', line 53

def error_response_with_oboe(error = {})
  status, headers, body = error_response_without_oboe(error)

  if Oboe.tracing?
    # Since Grape uses throw/catch and not Exceptions, we manually log
    # the error here.
    kvs = {}
    kvs[:ErrorClass] = 'GrapeError'
    kvs[:ErrorMsg] = error[:message] ? error[:message] : "No message given."
    kvs[:Backtrace] = ::Oboe::API.backtrace if Oboe::Config[:grape][:collect_backtraces]

    ::Oboe::API.log(nil, 'error', kvs)

    # Since calls to error() are handled similar to abort in Grape.  We
    # manually log the rack exit here since the original code won't
    # be returned to
    xtrace = Oboe::API.log_end('rack', :Status => status)

    if headers && Oboe::XTrace.valid?(xtrace)
      unless defined?(JRUBY_VERSION) && Oboe.is_continued_trace?
        headers['X-Trace'] = xtrace if headers.is_a?(Hash)
      end
    end
  end

  [status, headers, body]
end