Exception: Snitcher::API::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/snitcher/api/error.rb

Overview

Error is the base class for all API specific errors. For a full list of errors and how they can happen please refer to the API documentation.

deadmanssnitch.com/docs/api/v1#error-reference

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, message = nil, metadata = nil) ⇒ Error



34
35
36
37
38
39
# File 'lib/snitcher/api/error.rb', line 34

def initialize(type, message = nil,  = nil)
  super(message)

  @type     = type
   =  || {}
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/snitcher/api/error.rb', line 9

def type
  @type
end

Class Method Details

.new(api_error) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/snitcher/api/error.rb', line 11

def self.new(api_error)
  type    = api_error.delete("type")
  message = api_error.delete("error")

  klass =
    case type.to_s
      # sign_in_incorrect is only returned when using username + password.
      when "sign_in_incorrect";     AuthenticationError
      # api_key_invalid is only returned when using the API key.
      when "api_key_invalid";       AuthenticationError
      when "plan_limit_reached";    PlanLimitReachedError
      when "account_on_hold";       AccountOnHoldError
      when "resource_not_found";    ResourceNotFoundError
      when "resource_invalid";      ResourceInvalidError
      when "internal_server_error"; InternalServerError
      else                          Error
    end

  error = klass.allocate
  error.send(:initialize, type, message, api_error)
  error
end