Class: Beekeeper::ExceptionBlueprinter

Inherits:
Blueprinter::Base
  • Object
show all
Defined in:
lib/beekeeper/exception_blueprinter.rb

Class Method Summary collapse

Class Method Details

.get_error(exception, options) ⇒ Object



25
26
27
28
# File 'lib/beekeeper/exception_blueprinter.rb', line 25

def self.get_error exception, options
  status = get_status exception, options
  Rack::Utils::HTTP_STATUS_CODES.fetch(status, Rack::Utils::HTTP_STATUS_CODES[500])
end

.get_errors(exception) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/beekeeper/exception_blueprinter.rb', line 37

def self.get_errors exception
  return [
    {
      code: exception.class.name,
      message: exception.message
    }
  ]
end

.get_status(exception, options) ⇒ Object



21
22
23
# File 'lib/beekeeper/exception_blueprinter.rb', line 21

def self.get_status exception, options
  exception.try(:status) || get_status_from_backtrace(exception, options)
end

.get_status_from_backtrace(exception, options) ⇒ Object



30
31
32
33
34
35
# File 'lib/beekeeper/exception_blueprinter.rb', line 30

def self.get_status_from_backtrace exception, options
  request = options[:request]
  backtrace_cleaner = request.env['action_dispatch.backtrace_cleaner']
  wrapper = ::ActionDispatch::ExceptionWrapper.new(backtrace_cleaner, exception)
  return wrapper.status_code
end