Module: Marathon::Error
- Included in:
- Base, Connection
- Defined in:
- lib/marathon/error.rb
Overview
This module holds the Errors for the gem.
Defined Under Namespace
Classes: ArgumentError, AuthenticationError, ClientError, IOError, MarathonError, NotFoundError, TimeoutError, UnexpectedResponseError
Class Method Summary collapse
-
.error_class(response) ⇒ Object
Get reponse code specific error class.
-
.error_message(response) ⇒ Object
Get response code from http response.
-
.from_response(response) ⇒ Object
Raise error specific to http response.
Class Method Details
.error_class(response) ⇒ Object
Get reponse code specific error class. response
: HTTParty response object.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/marathon/error.rb', line 49 def error_class(response) case response.code when 400 ClientError when 422 ClientError when 404 NotFoundError else UnexpectedResponseError end end |
.error_message(response) ⇒ Object
Get response code from http response. response
: HTTParty response object.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/marathon/error.rb', line 64 def (response) body = response.parsed_response if not body.is_a?(Hash) body elsif body['message'] body['message'] elsif body['errors'] body['errors'] else body end rescue JSON::ParserError body end |
.from_response(response) ⇒ Object
Raise error specific to http response. response
: HTTParty response object.
39 40 41 42 43 |
# File 'lib/marathon/error.rb', line 39 def from_response(response) error_class(response).new((response)).tap do |err| err.response = response if err.is_a?(UnexpectedResponseError) end end |