Module: Notifications::Client::ErrorHandling

Included in:
Speaker
Defined in:
lib/notifications/client/request_error.rb

Instance Method Summary collapse

Instance Method Details

#build_error(response) ⇒ Object



35
36
37
# File 'lib/notifications/client/request_error.rb', line 35

def build_error(response)
  error_class_for_code(response.code.to_i).new(response)
end

#error_class_for_code(code) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/notifications/client/request_error.rb', line 39

def error_class_for_code(code)
  case code
  when 400
    BadRequestError
  when 403
    AuthError
  when 404
    NotFoundError
  when 429
    RateLimitError
  when (400..499)
    ClientError
  when (500..599)
    ServerError
  else
    RequestError
  end
end