Class: Sendly::ErrorFactory
- Inherits:
-
Object
- Object
- Sendly::ErrorFactory
- Defined in:
- lib/sendly/errors.rb
Overview
Convert API response to appropriate error
Class Method Summary collapse
Class Method Details
.from_response(status, body) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/sendly/errors.rb', line 97 def self.from_response(status, body) = body["message"] || body["error"] || "Unknown error" code = body["code"] details = body["details"] case status when 400, 422 ValidationError.new(, details: details) when 401 AuthenticationError.new() when 402 InsufficientCreditsError.new() when 404 NotFoundError.new() when 429 retry_after = body["retry_after"] || body["retryAfter"] RateLimitError.new(, retry_after: retry_after) when 500..599 ServerError.new(, status_code: status) else APIError.new(, status_code: status, code: code, details: details) end end |