Exception: Tradier::Error

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

Overview

Custom error class for rescuing from all Tradier errors

Direct Known Subclasses

ClientError, DecodeError, ServerError

Defined Under Namespace

Classes: BadGateway, BadRequest, ClientError, ConfigurationError, DecodeError, 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 = {}) ⇒ Tradier::Error

Initializes a new Error object

Parameters:

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


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

def initialize(exception=$!, 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/tradier/error.rb', line 4

def wrapped_exception
  @wrapped_exception
end

Class Method Details

.descendantsArray

Returns:

  • (Array)


15
16
17
# File 'lib/tradier/error.rb', line 15

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

.errorsHash

Returns:

  • (Hash)


7
8
9
10
11
12
# File 'lib/tradier/error.rb', line 7

def self.errors
  @errors ||= descendants.each_with_object({}) do |klass, hash|
    hash[klass::HTTP_STATUS_CODE] = klass if defined?(klass::HTTP_STATUS_CODE)
    hash.update(klass.errors)
  end
end

Instance Method Details

#backtraceObject



29
30
31
# File 'lib/tradier/error.rb', line 29

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