Exception: Smartbill::Sdk::APIError
- Defined in:
- lib/smartbill/sdk/api_error.rb
Overview
Raised when the SmartBill API returns an error envelope or a non-2xx response.
Instance Attribute Summary collapse
-
#error_text ⇒ String
readonly
The
errorTextfield from the API response. -
#message_field ⇒ String?
readonly
The optional
messagefield from the API. -
#status_code ⇒ Integer?
readonly
The HTTP status code, if available.
Instance Method Summary collapse
-
#initialize(error_text: "", message: nil, status_code: nil) ⇒ APIError
constructor
A new instance of APIError.
Constructor Details
#initialize(error_text: "", message: nil, status_code: nil) ⇒ APIError
Returns a new instance of APIError.
17 18 19 20 21 22 23 24 |
# File 'lib/smartbill/sdk/api_error.rb', line 17 def initialize(error_text: "", message: nil, status_code: nil) @error_text = error_text.to_s @message_field = @status_code = status_code detail = @error_text.empty? ? ( || "SmartBill API error") : @error_text detail = "[#{status_code}] #{detail}" unless status_code.nil? super(detail) end |
Instance Attribute Details
#error_text ⇒ String (readonly)
Returns the errorText field from the API response.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/smartbill/sdk/api_error.rb', line 14 class APIError < Error attr_reader :error_text, :message_field, :status_code def initialize(error_text: "", message: nil, status_code: nil) @error_text = error_text.to_s @message_field = @status_code = status_code detail = @error_text.empty? ? ( || "SmartBill API error") : @error_text detail = "[#{status_code}] #{detail}" unless status_code.nil? super(detail) end end |
#message_field ⇒ String? (readonly)
Returns the optional message field from the API.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/smartbill/sdk/api_error.rb', line 14 class APIError < Error attr_reader :error_text, :message_field, :status_code def initialize(error_text: "", message: nil, status_code: nil) @error_text = error_text.to_s @message_field = @status_code = status_code detail = @error_text.empty? ? ( || "SmartBill API error") : @error_text detail = "[#{status_code}] #{detail}" unless status_code.nil? super(detail) end end |
#status_code ⇒ Integer? (readonly)
Returns the HTTP status code, if available.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/smartbill/sdk/api_error.rb', line 14 class APIError < Error attr_reader :error_text, :message_field, :status_code def initialize(error_text: "", message: nil, status_code: nil) @error_text = error_text.to_s @message_field = @status_code = status_code detail = @error_text.empty? ? ( || "SmartBill API error") : @error_text detail = "[#{status_code}] #{detail}" unless status_code.nil? super(detail) end end |