Class: Veryfi::Error

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

Overview

Namespace + factory for every error raised by this SDK.

All errors inherit from VeryfiError, so callers that only need to know "something went wrong with Veryfi" can keep using:

begin client.document.process(file_path: path) rescue Veryfi::Error::VeryfiError => e # … end

Callers that want to react differently per HTTP status can rescue a more specific subclass:

begin client.document.process(file_path: path) rescue Veryfi::Error::Unauthorized then refresh_credentials! rescue Veryfi::Error::TooManyRequests then back_off rescue Veryfi::Error::ServerError then schedule_retry rescue Veryfi::Error::VeryfiError then log_and_raise end

Defined Under Namespace

Classes: AccessLimitReached, BadRequest, ClientError, Conflict, NotFound, RequestTimeout, ServerError, TooManyRequests, Unauthorized, UnsupportedMediaType, VeryfiError

Class Method Summary collapse

Class Method Details

.from_response(status, response) ⇒ VeryfiError

Build the right error subclass for the given HTTP status + response body. Always returns an instance of VeryfiError or one of its subclasses; never raises.

Parameters:

  • status (Integer)

    HTTP status code

  • response (Hash, Veryfi::Resource, nil)

    parsed JSON body

Returns:



93
94
95
96
97
98
# File 'lib/veryfi/error.rb', line 93

def self.from_response(status, response)
  klass = error_class_for(status)
  message = format_message(status, response)

  klass.new(message, response, status)
end