Exception: PaylocityWebService::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/paylocity_web_service/error.rb

Direct Known Subclasses

ClientError, ServerError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#responseObject

Returns the value of attribute response.


3
4
5
# File 'lib/paylocity_web_service/error.rb', line 3

def response
  @response
end

Class Method Details

.from_response(response) ⇒ PaylocityWebService::Error

Returns the appropriate PaylocityWebService::Error subclass based on status and response message

Parameters:

  • response (Hash)

    HTTP response

Returns:


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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