Exception: SignInService::Error

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

Direct Known Subclasses

ClientError, ServerError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Returns a new instance of Error.



27
28
29
30
31
32
33
# File 'lib/sign_in_service/error.rb', line 27

def initialize(response)
  @response = response
  @response_headers = response[:response_headers]
  @response_body = parsed_response_body
  @errors = fetch_errors
  super(error_message)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/sign_in_service/error.rb', line 5

def errors
  @errors
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/sign_in_service/error.rb', line 5

def response
  @response
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



5
6
7
# File 'lib/sign_in_service/error.rb', line 5

def response_body
  @response_body
end

#response_headersObject (readonly)

Returns the value of attribute response_headers.



5
6
7
# File 'lib/sign_in_service/error.rb', line 5

def response_headers
  @response_headers
end

Class Method Details

.from_response(response) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sign_in_service/error.rb', line 7

def self.from_response(response)
  status = response[:status].to_i

  klass = case status
          when 400 then BadRequest
          when 401 then Unauthorized
          when 403 then Forbidden
          when 404 then NotFound
          when 422 then UnprocessableEntity
          when 400..499 then ClientError
          when 500 then InternalServerError
          when 501 then NotImplemented
          when 502 then BadGateway
          when 503 then ServiceUnavailable
          when 500..599 then ServerError
          end

  klass&.new(response)
end