Exception: BerkeleyLibrary::TIND::API::APIException
- Inherits:
-
StandardError
- Object
- StandardError
- BerkeleyLibrary::TIND::API::APIException
- Defined in:
- lib/berkeley_library/tind/api/api_exception.rb
Overview
Wrapper for network-related exceptions.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#params ⇒ Hash?
readonly
The API query parameters, if any.
-
#response ⇒ RestClient::Response?
readonly
The response, if any.
-
#status_code ⇒ Integer?
readonly
The numeric HTTP status code, if any.
-
#status_message ⇒ String?
readonly
The HTTP status message, if any.
-
#url ⇒ String?
readonly
The request URI, if any.
Class Method Summary collapse
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(msg, **opts) ⇒ APIException
constructor
Initializes a new APIException.
Constructor Details
#initialize(msg, **opts) ⇒ APIException
Initializes a new APIException.
32 33 34 35 36 37 38 39 40 |
# File 'lib/berkeley_library/tind/api/api_exception.rb', line 32 def initialize(msg, **opts) super(msg) @url = opts[:url].to_s if opts.key?(:url) @params = opts[:params] @status_code, = format_status(opts[:status_code]) @status_message = opts[:status_message] || @response = opts[:response] end |
Instance Attribute Details
#params ⇒ Hash? (readonly)
Returns the API query parameters, if any.
12 13 14 |
# File 'lib/berkeley_library/tind/api/api_exception.rb', line 12 def params @params end |
#response ⇒ RestClient::Response? (readonly)
Returns the response, if any.
21 22 23 |
# File 'lib/berkeley_library/tind/api/api_exception.rb', line 21 def response @response end |
#status_code ⇒ Integer? (readonly)
Returns the numeric HTTP status code, if any.
15 16 17 |
# File 'lib/berkeley_library/tind/api/api_exception.rb', line 15 def status_code @status_code end |
#status_message ⇒ String? (readonly)
Returns the HTTP status message, if any.
18 19 20 |
# File 'lib/berkeley_library/tind/api/api_exception.rb', line 18 def @status_message end |
#url ⇒ String? (readonly)
Returns the request URI, if any.
9 10 11 |
# File 'lib/berkeley_library/tind/api/api_exception.rb', line 9 def url @url end |
Class Method Details
.wrap(ex, **opts) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/berkeley_library/tind/api/api_exception.rb', line 65 def wrap(ex, **opts) raise ArgumentError, "Can't wrap a nil error" unless ex msg = opts[:msg] || (ex, opts[:url], opts[:params], opts[:detail]) = (ex, opts[:url], opts[:params]) APIException.new(msg, **) end |
Instance Method Details
#body ⇒ Object
42 43 44 45 46 |
# File 'lib/berkeley_library/tind/api/api_exception.rb', line 42 def body return @body if instance_variable_defined?(:@body) @body = response && response.body end |