Exception: Footrest::HttpError::ErrorBase
- Inherits:
-
StandardError
- Object
- StandardError
- Footrest::HttpError::ErrorBase
- Defined in:
- lib/footrest/http_error.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#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.
Instance Method Summary collapse
- #errors ⇒ Object
- #headers ⇒ Object
-
#initialize(response = nil) ⇒ ErrorBase
constructor
A new instance of ErrorBase.
- #request_headers ⇒ Object
- #sanitized_request_headers ⇒ Object
- #status_message ⇒ Object
- #truncated_authorization_value ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(response = nil) ⇒ ErrorBase
Returns a new instance of ErrorBase.
10 11 12 13 14 15 16 17 |
# File 'lib/footrest/http_error.rb', line 10 def initialize(response=nil) @response = response @status = @response[:status] @body = @response[:body] @method = @response[:method] super("HTTP ERROR: #{status} (#{}) #{method} #{url}\n#{errors}\n#{headers}") end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/footrest/http_error.rb', line 8 def body @body end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
8 9 10 |
# File 'lib/footrest/http_error.rb', line 8 def method @method end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/footrest/http_error.rb', line 8 def response @response end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/footrest/http_error.rb', line 8 def status @status end |
Instance Method Details
#errors ⇒ Object
36 37 38 39 40 |
# File 'lib/footrest/http_error.rb', line 36 def errors JSON::pretty_generate(JSON::parse(@body)["errors"]) rescue @body end |
#headers ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/footrest/http_error.rb', line 27 def headers JSON::pretty_generate( request: sanitized_request_headers, response: @response.response_headers ) rescue => e "[Unable to show headers: #{e}]" end |
#request_headers ⇒ Object
51 52 53 |
# File 'lib/footrest/http_error.rb', line 51 def request_headers @response.request_headers end |
#sanitized_request_headers ⇒ Object
46 47 48 49 |
# File 'lib/footrest/http_error.rb', line 46 def sanitized_request_headers return request_headers unless request_headers['Authorization'] request_headers.merge('Authorization' => ) end |
#status_message ⇒ Object
42 43 44 |
# File 'lib/footrest/http_error.rb', line 42 def HTTP_STATUS_CODES.fetch(status, 'UNKNOWN STATUS') end |
#truncated_authorization_value ⇒ Object
55 56 57 58 59 60 |
# File 'lib/footrest/http_error.rb', line 55 def bearer, token = request_headers['Authorization'].split(/\s+/) token_parts = token.split('~') token_parts[-1] = token_parts.last[0, 4] "Bearer #{token_parts.join('~')}..." end |
#url ⇒ Object
23 24 25 |
# File 'lib/footrest/http_error.rb', line 23 def url @response.url.to_s end |