Exception: DianPing::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/dianping/error.rb,
lib/dianping/error/not_found.rb,
lib/dianping/error/client_error.rb

Overview

Custom error class for rescuing from all DianPing errors

Direct Known Subclasses

ClientError

Defined Under Namespace

Classes: ClientError, NotFound

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception = $!, response_headers = {}) ⇒ DianPing::Error

Initializes a new Error object

Parameters:

  • exception (Exception, String) (defaults to: $!)
  • response_headers (Hash) (defaults to: {})


20
21
22
# File 'lib/dianping/error.rb', line 20

def initialize(exception=$!, response_headers={})
  exception.respond_to?(:backtrace) ? super(exception.message) : super(exception.to_s)
end

Class Method Details

.descendantsArray

Returns:

  • (Array)


11
12
13
# File 'lib/dianping/error.rb', line 11

def self.descendants
  ObjectSpace.each_object(::Class).select{|klass| klass < self}
end

.errorsHash

Returns:

  • (Hash)


6
7
8
# File 'lib/dianping/error.rb', line 6

def self.errors
  @errors ||= Hash[descendants.map{|klass| [klass.const_get(:HTTP_STATUS_CODE)]}]
end

Instance Method Details

#backtraceObject



24
25
26
# File 'lib/dianping/error.rb', line 24

def backtrace
  @wrapped_exception.respond_to?(:backtrace) ? @wrapped_exception.backtrace : super
end