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

Returns a new instance of Error.



31
32
33
34
35
36
# File 'lib/snitcher/api/error.rb', line 31

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

  @type     = type
  @metadata =  || {}
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.new(api_error) ⇒ Object



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

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
      else                       Error
    end

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