Module: Jersey::Extensions::ErrorHandler

Defined in:
lib/jersey/extensions/error_handler.rb

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jersey/extensions/error_handler.rb', line 3

def self.registered(app)
  app.set :dump_errors, false
  app.set :raise_errors, false
  app.set :show_exceptions, false

  # APIS should always return meaningful standardized errors
  # with statuses that best match HTTP conventions
  #
  # Places nicely with Jersey::HTTP::Errors
  app.error do
    content_type(:json)
    e = env['sinatra.error']
    # get status code from Jersey Errors
    if e.class.const_defined?(:STATUS_CODE)
      status(e.class::STATUS_CODE)
    else
      status(500)
    end

    json(error: {
      type: e.class.name.split('::').last,
      request_id: env['REQUEST_ID'],
      message: e.message,
      backtrace: e.backtrace
    })
  end
end