Exception: Candid::Errors::ResponseError

Inherits:
ApiError
  • Object
show all
Defined in:
lib/candid/errors/response_error.rb

Direct Known Subclasses

ClientError, RedirectError, ServerError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg, code:) ⇒ ResponseError

Returns a new instance of ResponseError.



8
9
10
11
# File 'lib/candid/errors/response_error.rb', line 8

def initialize(msg, code:)
  @code = code
  super(msg)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/candid/errors/response_error.rb', line 6

def code
  @code
end

Class Method Details

.subclass_for_code(code) ⇒ Class

Returns the most appropriate error class for the given code.

Returns:

  • (Class)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/candid/errors/response_error.rb', line 20

def self.subclass_for_code(code)
  case code
  when 300..399
    RedirectError
  when 401
    UnauthorizedError
  when 403
    ForbiddenError
  when 404
    NotFoundError
  when 400..499
    ClientError
  when 503
    ServiceUnavailableError
  when 500..599
    ServerError
  else
    ResponseError
  end
end

Instance Method Details

#inspectObject



13
14
15
# File 'lib/candid/errors/response_error.rb', line 13

def inspect
  "#<#{self.class.name} @code=#{code} @body=#{message}>"
end