Exception: AhoSdk::ApiError
- Inherits:
-
StandardError
- Object
- StandardError
- AhoSdk::ApiError
- Defined in:
- lib/aho_sdk/http_client.rb
Overview
Base error class for API errors
Direct Known Subclasses
AuthenticationError, BadRequestError, ConflictError, ForbiddenError, NotFoundError, RateLimitError, ServerError, ValidationError
Instance Attribute Summary collapse
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
-
#raw_body ⇒ Object
readonly
Returns the value of attribute raw_body.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Instance Method Summary collapse
-
#initialize(body, status_code, request_id = nil) ⇒ ApiError
constructor
A new instance of ApiError.
Constructor Details
#initialize(body, status_code, request_id = nil) ⇒ ApiError
Returns a new instance of ApiError.
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/aho_sdk/http_client.rb', line 334 def initialize(body, status_code, request_id = nil) @status_code = status_code @request_id = request_id @raw_body = body begin parsed = JSON.parse(body, symbolize_names: true) error = parsed[:error] || parsed @error_code = error[:code] @details = normalize_details(error[:details]) super(error[:message] || body) rescue JSON::ParserError @error_code = "unknown" @details = [] super(body) end end |
Instance Attribute Details
#details ⇒ Object (readonly)
Returns the value of attribute details.
332 333 334 |
# File 'lib/aho_sdk/http_client.rb', line 332 def details @details end |
#error_code ⇒ Object (readonly)
Returns the value of attribute error_code.
332 333 334 |
# File 'lib/aho_sdk/http_client.rb', line 332 def error_code @error_code end |
#raw_body ⇒ Object (readonly)
Returns the value of attribute raw_body.
332 333 334 |
# File 'lib/aho_sdk/http_client.rb', line 332 def raw_body @raw_body end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
332 333 334 |
# File 'lib/aho_sdk/http_client.rb', line 332 def request_id @request_id end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
332 333 334 |
# File 'lib/aho_sdk/http_client.rb', line 332 def status_code @status_code end |