Exception: EasyDocForms::APIError
- Defined in:
- lib/easydocforms/errors.rb
Overview
An API-level failure: the request reached EasyDocForms and was rejected. Transport failures raise their ordinary Ruby exceptions instead.
Direct Known Subclasses
AuthenticationError, NotFoundError, PDFPendingError, PermissionError, RateLimitError
Constant Summary collapse
- PARTNER_API_NOT_ENABLED =
Machine-readable codes on authorization failures.
"PARTNER_API_NOT_ENABLED"- SCOPE_REQUIRED =
"SCOPE_REQUIRED"
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#completed_pdf_status ⇒ Object
readonly
Returns the value of attribute completed_pdf_status.
-
#hint ⇒ Object
readonly
Returns the value of attribute hint.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Class Method Summary collapse
-
.from_response(status_code, body) ⇒ Object
Builds the right error subclass from an HTTP error response.
Instance Method Summary collapse
-
#initialize(message, status_code:, code: nil, hint: nil, completed_pdf_status: nil) ⇒ APIError
constructor
A new instance of APIError.
Constructor Details
#initialize(message, status_code:, code: nil, hint: nil, completed_pdf_status: nil) ⇒ APIError
Returns a new instance of APIError.
19 20 21 22 23 24 25 |
# File 'lib/easydocforms/errors.rb', line 19 def initialize(, status_code:, code: nil, hint: nil, completed_pdf_status: nil) super() @status_code = status_code @code = code @hint = hint @completed_pdf_status = completed_pdf_status end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
17 18 19 |
# File 'lib/easydocforms/errors.rb', line 17 def code @code end |
#completed_pdf_status ⇒ Object (readonly)
Returns the value of attribute completed_pdf_status.
17 18 19 |
# File 'lib/easydocforms/errors.rb', line 17 def completed_pdf_status @completed_pdf_status end |
#hint ⇒ Object (readonly)
Returns the value of attribute hint.
17 18 19 |
# File 'lib/easydocforms/errors.rb', line 17 def hint @hint end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
17 18 19 |
# File 'lib/easydocforms/errors.rb', line 17 def status_code @status_code end |
Class Method Details
.from_response(status_code, body) ⇒ Object
Builds the right error subclass from an HTTP error response.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/easydocforms/errors.rb', line 28 def self.from_response(status_code, body) parsed = begin JSON.parse(body.to_s) rescue JSON::ParserError {} end parsed = {} unless parsed.is_a?(Hash) = parsed["error"] || "HTTP #{status_code}" attrs = { status_code: status_code, code: parsed["code"], hint: parsed["hint"], completed_pdf_status: parsed["completed_pdf_status"] } klass = case status_code when 401 then AuthenticationError when 403 then PermissionError when 404 then NotFoundError when 409 then parsed["completed_pdf_status"] == "pending" ? PDFPendingError : APIError when 429 then RateLimitError else APIError end klass.new(, **attrs) end |