Exception: Fantasydata::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/fantasydata/error.rb,
lib/fantasydata/error/forbidden.rb,
lib/fantasydata/error/not_found.rb,
lib/fantasydata/error/bad_gateway.rb,
lib/fantasydata/error/bad_request.rb,
lib/fantasydata/error/client_error.rb,
lib/fantasydata/error/server_error.rb,
lib/fantasydata/error/unauthorized.rb,
lib/fantasydata/error/not_acceptable.rb,
lib/fantasydata/error/gateway_timeout.rb,
lib/fantasydata/error/too_many_requests.rb,
lib/fantasydata/error/configuration_error.rb,
lib/fantasydata/error/service_unavailable.rb,
lib/fantasydata/error/unprocessable_entity.rb,
lib/fantasydata/error/internal_server_error.rb

Overview

Custom error class for rescuing from all Fantasydata errors

Direct Known Subclasses

ClientError, ServerError

Defined Under Namespace

Classes: BadGateway, BadRequest, ClientError, ConfigurationError, Forbidden, GatewayTimeout, InternalServerError, NotAcceptable, NotFound, ServerError, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity

Constant Summary collapse

EnhanceYourCalm =
TooManyRequests
RateLimited =
TooManyRequests

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes a new Error object

Parameters:

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


22
23
24
25
26
# File 'lib/fantasydata/error.rb', line 22

def initialize(exception=$!, response_headers={})
  # @rate_limit = Fantasydata::RateLimit.new(response_headers)
  @wrapped_exception = exception
  exception.respond_to?(:backtrace) ? super(exception.message) : super(exception.to_s)
end

Instance Attribute Details

#wrapped_exceptionObject (readonly)

Returns the value of attribute wrapped_exception.



4
5
6
# File 'lib/fantasydata/error.rb', line 4

def wrapped_exception
  @wrapped_exception
end

Class Method Details

.descendantsArray

Returns:

  • (Array)


13
14
15
# File 'lib/fantasydata/error.rb', line 13

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

.errorsHash

Returns:

  • (Hash)


8
9
10
# File 'lib/fantasydata/error.rb', line 8

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

Instance Method Details

#backtraceObject



28
29
30
# File 'lib/fantasydata/error.rb', line 28

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