Exception: SignWell::ApiStatusError

Inherits:
ApiError
  • Object
show all
Defined in:
lib/signwell_sdk/api_error.rb

Overview

Raised when the API returns a non-success HTTP status code. Use ApiStatusError.for to construct the appropriate subclass.

Instance Attribute Summary

Attributes inherited from ApiError

#body, #code, #response_body, #response_headers

Class Method Summary collapse

Methods inherited from ApiError

#initialize, #message, #to_s

Constructor Details

This class inherits a constructor from SignWell::ApiError

Class Method Details

.for(code:, response_headers: nil, response_body: nil, message: nil) ⇒ ApiStatusError

Factory method that returns the appropriate error subclass based on the HTTP status code.

Parameters:

  • code (Integer)

    HTTP status code

  • response_headers (Hash) (defaults to: nil)

    Response headers

  • response_body (String) (defaults to: nil)

    Raw response body

  • message (String) (defaults to: nil)

    Error message

Returns:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/signwell_sdk/api_error.rb', line 80

def self.for(code:, response_headers: nil, response_body: nil, message: nil)
  klass = case code
          when 400 then BadRequestError
          when 401 then AuthenticationError
          when 403 then PermissionDeniedError
          when 404 then NotFoundError
          when 409 then ConflictError
          when 422 then UnprocessableEntityError
          when 429 then RateLimitError
          else
            code >= 500 ? InternalServerError : ApiStatusError
          end

  klass.new(
    code: code,
    response_headers: response_headers,
    response_body: response_body,
    message: message
  )
end