Exception: BoletoSimples::ResponseError
- Inherits:
-
StandardError
- Object
- StandardError
- BoletoSimples::ResponseError
- Defined in:
- lib/boletosimples/response_error.rb
Overview
BoletoSimples::ResponseError Exception that gets raised if the response is an error (4xx or 5xx)
Formats a readable error message including HTTP status, method and requested URL
Examples:
BoletoSimples::BankBillet.all
BoletoSimples::ResponseError: 401 POST https://api-sandbox.kobana.com.br/v1/bank_billets
begin
BoletoSimples::BankBillet.all
rescue BoletoSimples::ResponseError => response
response.status # => 401
response.method # => "GET"
response.url # => "https://api-sandbox.kobana.com.br/v1/bank_billets"
response.body # => "{"error":"VocĂȘ precisa se logar ou registrar antes de prosseguir."}"
response.error_message # => "VocĂȘ precisa se logar ou registrar antes de prosseguir."
end
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(response = nil) ⇒ ResponseError
constructor
A new instance of ResponseError.
- #to_s ⇒ Object
Constructor Details
#initialize(response = nil) ⇒ ResponseError
Returns a new instance of ResponseError.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/boletosimples/response_error.rb', line 27 def initialize(response = nil) @response = response @body = response[:body][:data] @status = response[:status].to_i @method = response[:method].to_s.upcase @url = response[:url] errors = response[:body][:errors] @error_message = errors.first[:title] unless errors.blank? super end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
25 26 27 |
# File 'lib/boletosimples/response_error.rb', line 25 def body @body end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
25 26 27 |
# File 'lib/boletosimples/response_error.rb', line 25 def @error_message end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
25 26 27 |
# File 'lib/boletosimples/response_error.rb', line 25 def method @method end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
25 26 27 |
# File 'lib/boletosimples/response_error.rb', line 25 def response @response end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
25 26 27 |
# File 'lib/boletosimples/response_error.rb', line 25 def status @status end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
25 26 27 |
# File 'lib/boletosimples/response_error.rb', line 25 def url @url end |
Instance Method Details
#to_s ⇒ Object
41 42 43 44 45 46 |
# File 'lib/boletosimples/response_error.rb', line 41 def to_s msg = '' msg += "#{status} #{method} #{url}" msg << " (#{})" unless .blank? msg end |