class PaylocityWebService::Error
Attributes
response[RW]
Public Class Methods
from_response(response)
click to toggle source
Returns the appropriate PaylocityWebService::Error
subclass based on status and response message
@param [Hash] response HTTP response @return [PaylocityWebService::Error]
# File lib/paylocity_web_service/error.rb, line 10 def self.from_response(response) status = response[:status].to_i if klass = case status when 400 PaylocityWebService::BadRequest when 401 PaylocityWebService::ClientError when 403 PaylocityWebService::Forbidden when 404 PaylocityWebService::NotFound when 405 PaylocityWebService::MethodNotAllowed when 406 PaylocityWebService::NotAcceptable when 409 PaylocityWebService::Conflict when 415 PaylocityWebService::UnsupportedMediaType when 422 PaylocityWebService::UnprocessableEntity when 451 PaylocityWebService::UnavailableForLegalReasons when 400..499 PaylocityWebService::ClientError when 500 PaylocityWebService::InternalServerError when 501 PaylocityWebService::NotImplemented when 502 PaylocityWebService::BadGateway when 503 PaylocityWebService::ServiceUnavailable when 500..599 PaylocityWebService::ServerError end klass.new(response) end end
new(response=nil)
click to toggle source
Calls superclass method
# File lib/paylocity_web_service/error.rb, line 54 def initialize(response=nil) @response = response super(build_error_message) end
Private Instance Methods
build_error_message()
click to toggle source
# File lib/paylocity_web_service/error.rb, line 59 def build_error_message return nil if response.nil? message = "Status: #{response&.status} \n" message << "Method: #{response&.method&.to_s.upcase} \n" message << "URL: #{response&.url&.to_s} \n" message << "Body: \n" message << JSON.pretty_generate(response&.body) message # message = { # status: response.status, # headers: response.response_headers, # body: response.body, # request: { # method: response.method, # url_path: response.url.path, # params: response.params, # headers: response.request_headers, # body: response.request_body # } # } # JSON.pretty_generate(message) end
response.method,()
click to toggle source
message = {
status: response.status, headers: response.response_headers, body: response.body, request: { url_path: response.url.path, params: response.params, headers: response.request_headers, body: response.request_body }
} JSON.pretty_generate(message)
# File lib/paylocity_web_service/error.rb, line 74