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.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/marathon/error.rb', line 38 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.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/marathon/error.rb', line 53 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 end |
.from_response(response) ⇒ Object
Raise error specific to http response. response
: HTTParty response object.
30 31 32 |
# File 'lib/marathon/error.rb', line 30 def from_response(response) error_class(response).new((response)) end |