Exception: EtCcdClient::Exceptions::Base
- Inherits:
-
StandardError
- Object
- StandardError
- EtCcdClient::Exceptions::Base
- Defined in:
- lib/et_ccd_client/exceptions/base.rb
Direct Known Subclasses
Forbidden, GatewayTimeout, InternalServerError, NotFound, Unauthorized, UnprocessableEntity
Instance Attribute Summary collapse
-
#original_exception ⇒ Object
readonly
Returns the value of attribute original_exception.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(original_exception, url: nil, request: nil) ⇒ Base
constructor
A new instance of Base.
- #response ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(original_exception, url: nil, request: nil) ⇒ Base
Returns a new instance of Base.
19 20 21 22 23 |
# File 'lib/et_ccd_client/exceptions/base.rb', line 19 def initialize(original_exception, url: nil, request: nil) self.original_exception = original_exception self.url = url self.request = request end |
Instance Attribute Details
#original_exception ⇒ Object
Returns the value of attribute original_exception.
4 5 6 |
# File 'lib/et_ccd_client/exceptions/base.rb', line 4 def original_exception @original_exception end |
#request ⇒ Object
Returns the value of attribute request.
4 5 6 |
# File 'lib/et_ccd_client/exceptions/base.rb', line 4 def request @request end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/et_ccd_client/exceptions/base.rb', line 4 def url @url end |
Class Method Details
.exception(*args, **kw_args) ⇒ Object
15 16 17 |
# File 'lib/et_ccd_client/exceptions/base.rb', line 15 def self.exception(*args, **kw_args) new(*args, **kw_args) end |
.raise_exception(original_exception, **kw_args) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/et_ccd_client/exceptions/base.rb', line 6 def self.raise_exception(original_exception, **kw_args) expected_error_class = original_exception.class.name.split('::').last if EtCcdClient::Exceptions.const_defined?(expected_error_class) raise EtCcdClient::Exceptions.const_get(expected_error_class).new original_exception, **kw_args else raise new(original_exception, **kw_args) end end |
Instance Method Details
#response ⇒ Object
25 26 27 |
# File 'lib/et_ccd_client/exceptions/base.rb', line 25 def response original_exception.response end |
#to_s ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/et_ccd_client/exceptions/base.rb', line 29 def to_s json = JSON.parse(response.body) rescue JSON::JSONError = if json.nil? || json == JSON::JSONError '' else json['message'] || json['error'] || '' end if url "#{original_exception.} - #{} ('#{url}')" else "#{original_exception.} - #{}" end end |