Exception: Staddress::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Staddress::Error
- Defined in:
- lib/staddress/errors.rb
Overview
Staddress API 呼び出しで発生したエラーを表す統一例外。
- HTTP 4xx / 5xx で API がエラーボディを返した場合
- ネットワークエラー・タイムアウト(code: "network_error" / "timeout")
- 入力バリデーションエラー(code: "invalid_request")
属性:
code API エラーコード("unauthorized", "quota_exceeded" 等)
http_status HTTP ステータスコード(ネットワークエラー時は 0)
request_id サポート問い合わせ用のリクエスト ID(あれば)
retry_after 再試行可能日時(ISO 8601、あれば)
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#http_status ⇒ Object
readonly
Returns the value of attribute http_status.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#retry_after ⇒ Object
readonly
Returns the value of attribute retry_after.
Class Method Summary collapse
-
.from_body(body, http_status) ⇒ Object
API のエラーボディ(Hash)から Error を生成する。.
Instance Method Summary collapse
-
#initialize(message, code: "internal_error", http_status: 0, request_id: nil, retry_after: nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(message, code: "internal_error", http_status: 0, request_id: nil, retry_after: nil) ⇒ Error
Returns a new instance of Error.
18 19 20 21 22 23 24 |
# File 'lib/staddress/errors.rb', line 18 def initialize(, code: "internal_error", http_status: 0, request_id: nil, retry_after: nil) super() @code = code @http_status = http_status @request_id = request_id @retry_after = retry_after end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
16 17 18 |
# File 'lib/staddress/errors.rb', line 16 def code @code end |
#http_status ⇒ Object (readonly)
Returns the value of attribute http_status.
16 17 18 |
# File 'lib/staddress/errors.rb', line 16 def http_status @http_status end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
16 17 18 |
# File 'lib/staddress/errors.rb', line 16 def request_id @request_id end |
#retry_after ⇒ Object (readonly)
Returns the value of attribute retry_after.
16 17 18 |
# File 'lib/staddress/errors.rb', line 16 def retry_after @retry_after end |
Class Method Details
.from_body(body, http_status) ⇒ Object
API のエラーボディ(Hash)から Error を生成する。
27 28 29 30 31 32 33 34 35 |
# File 'lib/staddress/errors.rb', line 27 def self.from_body(body, http_status) new( body["message"] || "API error (#{body["code"]})", code: body["code"], http_status: http_status, request_id: body["requestId"], retry_after: body["retryAfter"] ) end |