Class: Veryfi::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/veryfi/error.rb

Defined Under Namespace

Classes: AccessLimitReached, BadRequest, InternalError, ResourceNotFound, UnauthorizedAccessToken, UnexpectedHTTPMethod, VeryfiError

Class Method Summary collapse

Class Method Details

.from_response(status, response) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/veryfi/error.rb', line 5

def self.from_response(status, response)
  if response.empty?
    VeryfiError.new(format("%<code>d", code: status))
  else
    get_error(status, response)
  end
end

.get_error(status, response) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/veryfi/error.rb', line 13

def self.get_error(status, response)
  case status
  when 400 then BadRequest
  when 401 then UnauthorizedAccessToken
  when 404 then ResourceNotFound
  when 405 then UnexpectedHTTPMethod
  when 409 then AccessLimitReached
  when 500 then InternalError
  else VeryfiError.new(format("%<code>d, %<message>s", code: status, message: response["error"]))
  end
end