Exception: StartupStats::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/startupstats/error.rb,
lib/startupstats/error/forbidden.rb,
lib/startupstats/error/not_found.rb,
lib/startupstats/error/bad_gateway.rb,
lib/startupstats/error/bad_request.rb,
lib/startupstats/error/client_error.rb,
lib/startupstats/error/decode_error.rb,
lib/startupstats/error/params_error.rb,
lib/startupstats/error/server_error.rb,
lib/startupstats/error/unauthorized.rb,
lib/startupstats/error/not_acceptable.rb,
lib/startupstats/error/gateway_timeout.rb,
lib/startupstats/error/internal_server_error.rb

Overview

Custom error class for rescuing from all StartupStats errors

Direct Known Subclasses

ClientError, DecodeError, ParamsError, ServerError

Defined Under Namespace

Classes: BadGateway, BadRequest, ClientError, DecodeError, Forbidden, GatewayTimeout, InternalServerError, NotAcceptable, NotFound, ParamsError, ServerError, Unauthorized

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes a new Error object

Parameters:

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


21
22
23
24
# File 'lib/startupstats/error.rb', line 21

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/startupstats/error.rb', line 4

def wrapped_exception
  @wrapped_exception
end

Class Method Details

.descendantsArray

Returns:

  • (Array)


12
13
14
# File 'lib/startupstats/error.rb', line 12

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

.errorsHash

Returns:



7
8
9
# File 'lib/startupstats/error.rb', line 7

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

Instance Method Details

#backtraceObject



26
27
28
# File 'lib/startupstats/error.rb', line 26

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