Module: Camdram::Error

Defined in:
lib/camdram/error.rb

Defined Under Namespace

Classes: BadRequest, CamdramError, ClientError, Forbidden, NoApiKey, NotFound, RateLimit, RedirectError, ServerError, Unauthorized

Class Method Summary collapse

Class Method Details

.for(response) ⇒ Object

This is called by the HTTP class when a request is not successful and is not a redirect



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/camdram/error.rb', line 55

def self.for(response)
  code = response.code.to_i
  error_class = case code
                when 300..399
                  RedirectError
                when 400
                  BadRequest
                when 403
                  Forbidden
                when 404
                  NotFound
                when 401
                  Unauthorized
                when 429
                  RateLimit
                when 400..499
                  ClientError
                else
                  CamdramError
                end
  error_class.new(code, response.body, response.header)
end