Exception: MixinBot::APIError
- Defined in:
- lib/mixin_bot/errors.rb
Overview
Base class for Mixin API error responses with structured metadata.
Direct Known Subclasses
AppUpdateRequiredError, ConflictError, ForbiddenError, InsufficientBalanceError, InsufficientPoolError, InvalidAddressFormatError, NotFoundError, PinError, RateLimitError, ResponseError, ServerError, TransferError, TransientError, UnauthorizedError, UserNotFoundError, ValidationError
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#extra ⇒ Object
readonly
Returns the value of attribute extra.
-
#http_status ⇒ Object
readonly
Returns the value of attribute http_status.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#retry_after ⇒ Object
readonly
Returns the value of attribute retry_after.
-
#server_time ⇒ Object
readonly
Returns the value of attribute server_time.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Class Method Summary collapse
Instance Method Summary collapse
-
#client_error? ⇒ Boolean
rubocop:enable Metrics/ParameterLists.
- #formatted_message ⇒ Object
-
#initialize(message = nil, code: nil, description: nil, status: nil, http_status: nil, request_id: nil, server_time: nil, retry_after: nil, extra: nil, path: nil, verb: nil, body: nil) ⇒ APIError
constructor
rubocop:disable Metrics/ParameterLists – structured API error metadata.
- #retryable? ⇒ Boolean
- #throttle? ⇒ Boolean
Constructor Details
#initialize(message = nil, code: nil, description: nil, status: nil, http_status: nil, request_id: nil, server_time: nil, retry_after: nil, extra: nil, path: nil, verb: nil, body: nil) ⇒ APIError
rubocop:disable Metrics/ParameterLists – structured API error metadata
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mixin_bot/errors.rb', line 32 def initialize( = nil, code: nil, description: nil, status: nil, http_status: nil, request_id: nil, server_time: nil, retry_after: nil, extra: nil, path: nil, verb: nil, body: nil) @code = code&.to_i @description = description @status = status&.to_i @http_status = http_status&.to_i @request_id = request_id @server_time = server_time @retry_after = retry_after @extra = extra @path = path @verb = verb @body = body super( || ) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
28 29 30 |
# File 'lib/mixin_bot/errors.rb', line 28 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
28 29 30 |
# File 'lib/mixin_bot/errors.rb', line 28 def code @code end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
28 29 30 |
# File 'lib/mixin_bot/errors.rb', line 28 def description @description end |
#extra ⇒ Object (readonly)
Returns the value of attribute extra.
28 29 30 |
# File 'lib/mixin_bot/errors.rb', line 28 def extra @extra end |
#http_status ⇒ Object (readonly)
Returns the value of attribute http_status.
28 29 30 |
# File 'lib/mixin_bot/errors.rb', line 28 def http_status @http_status end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
28 29 30 |
# File 'lib/mixin_bot/errors.rb', line 28 def path @path end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
28 29 30 |
# File 'lib/mixin_bot/errors.rb', line 28 def request_id @request_id end |
#retry_after ⇒ Object (readonly)
Returns the value of attribute retry_after.
28 29 30 |
# File 'lib/mixin_bot/errors.rb', line 28 def retry_after @retry_after end |
#server_time ⇒ Object (readonly)
Returns the value of attribute server_time.
28 29 30 |
# File 'lib/mixin_bot/errors.rb', line 28 def server_time @server_time end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
28 29 30 |
# File 'lib/mixin_bot/errors.rb', line 28 def status @status end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
28 29 30 |
# File 'lib/mixin_bot/errors.rb', line 28 def verb @verb end |
Class Method Details
.build(klass, verb:, path:, body:, response:, result:, code: nil, description: nil) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/mixin_bot/errors.rb', line 81 def build(klass, verb:, path:, body:, response:, result:, code: nil, description: nil) err = result.is_a?(Hash) ? (result['error'] || {}) : {} resolved_code = code || err['code'] || infer_code_from_http(response) resolved_description = description || err['description'] || http_status_description(response&.status) headers = response&.headers || {} retry_after = headers['Retry-After'] if klass <= RateLimitError klass.new( code: resolved_code, description: resolved_description, status: err['status'], http_status: response&.status, request_id: headers['X-Request-Id'], server_time: headers['X-Server-Time'], retry_after: retry_after, extra: err['extra'], path: path, verb: verb, body: body ) end |
Instance Method Details
#client_error? ⇒ Boolean
rubocop:enable Metrics/ParameterLists
50 51 52 53 54 55 56 |
# File 'lib/mixin_bot/errors.rb', line 50 def client_error? c = code.to_i return true if c.between?(400, 499) return true if http_status == 202 && c.positive? && c < 500 false end |
#formatted_message ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mixin_bot/errors.rb', line 66 def format( '%<verb>s | %<path>s | %<body>s, errcode: %<code>s, errmsg: %<description>s, ' \ 'request_id: %<request_id>s, server_time: %<server_time>s', verb: verb.to_s.upcase, path: path.to_s, body: body.to_s, code: code, description: description, request_id: request_id, server_time: server_time ) end |
#retryable? ⇒ Boolean
58 59 60 |
# File 'lib/mixin_bot/errors.rb', line 58 def retryable? false end |
#throttle? ⇒ Boolean
62 63 64 |
# File 'lib/mixin_bot/errors.rb', line 62 def throttle? false end |