module Marathon::Error
This module holds the Errors for the gem.
Public Class Methods
error_class(response)
click to toggle source
Get reponse code specific error class. response
: HTTParty response object.
# 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)
click to toggle source
Get response code from http response. response
: HTTParty response object.
# File lib/marathon/error.rb, line 64 def error_message(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)
click to toggle source
Raise error specific to http response. response
: HTTParty response object.
# File lib/marathon/error.rb, line 39 def from_response(response) error_class(response).new(error_message(response)).tap do |err| err.response = response if err.is_a?(UnexpectedResponseError) end end
Private Instance Methods
error_class(response)
click to toggle source
Get reponse code specific error class. response
: HTTParty response object.
# 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)
click to toggle source
Get response code from http response. response
: HTTParty response object.
# File lib/marathon/error.rb, line 64 def error_message(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)
click to toggle source
Raise error specific to http response. response
: HTTParty response object.
# File lib/marathon/error.rb, line 39 def from_response(response) error_class(response).new(error_message(response)).tap do |err| err.response = response if err.is_a?(UnexpectedResponseError) end end