Exception: Infisical::APIError
- Defined in:
- lib/infisical/errors.rb
Overview
Raised when the Infisical API responds with a non-2xx status. Well-known statuses raise a subclass (AuthenticationError, PermissionError, NotFoundError, RateLimitError, ServerError); rescuing this class catches them all.
Direct Known Subclasses
AuthenticationError, NotFoundError, PermissionError, RateLimitError, ServerError
Instance Attribute Summary collapse
-
#http_method ⇒ String
readonly
Uppercase HTTP method of the failed request, e.g.
-
#request_id ⇒ String?
readonly
Server-assigned request id, when the response carried one.
-
#status ⇒ Integer
readonly
HTTP status code of the failed response.
-
#url ⇒ String
readonly
Full URL the failed request was sent to.
Class Method Summary collapse
-
.for_status(status) ⇒ Class<APIError>
Returns the error class that best matches an HTTP status, falling back to APIError itself.
Instance Method Summary collapse
-
#initialize(message, status:, url:, http_method:, request_id: nil) ⇒ APIError
constructor
A new instance of APIError.
Constructor Details
#initialize(message, status:, url:, http_method:, request_id: nil) ⇒ APIError
Returns a new instance of APIError.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/infisical/errors.rb', line 47 def initialize(, status:, url:, http_method:, request_id: nil) @status = status @url = url @http_method = http_method @request_id = request_id context = "[Method=#{http_method}] [URL=#{url}] [StatusCode=#{status}]" context += " [RequestId=#{request_id}]" if request_id super("#{context} #{}") end |
Instance Attribute Details
#http_method ⇒ String (readonly)
Returns uppercase HTTP method of the failed request, e.g. "GET".
20 21 22 |
# File 'lib/infisical/errors.rb', line 20 def http_method @http_method end |
#request_id ⇒ String? (readonly)
Returns server-assigned request id, when the response carried one.
23 24 25 |
# File 'lib/infisical/errors.rb', line 23 def request_id @request_id end |
#status ⇒ Integer (readonly)
Returns HTTP status code of the failed response.
14 15 16 |
# File 'lib/infisical/errors.rb', line 14 def status @status end |
#url ⇒ String (readonly)
Returns full URL the failed request was sent to.
17 18 19 |
# File 'lib/infisical/errors.rb', line 17 def url @url end |
Class Method Details
.for_status(status) ⇒ Class<APIError>
Returns the error class that best matches an HTTP status, falling back to Infisical::APIError itself. Constants are resolved at call time, so the subclasses defined below are visible here.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/infisical/errors.rb', line 31 def self.for_status(status) case status when 401 then AuthenticationError when 403 then PermissionError when 404 then NotFoundError when 429 then RateLimitError when 500..599 then ServerError else self end end |