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.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/marathon/error.rb', line 46 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.
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/marathon/error.rb', line 61 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.
38 39 40 |
# File 'lib/marathon/error.rb', line 38 def from_response(response) error_class(response).new((response)) end |