Exception: Teamtailor::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Teamtailor::Error
- Defined in:
- lib/teamtailor/error.rb
Direct Known Subclasses
Class Method Summary collapse
Class Method Details
.from_response(body:, status:) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/teamtailor/error.rb', line 5 def self.from_response(body:, status:) json_response = parse_body(body) = json_response.dig("errors", 0, "detail") || json_response.dig("errors", "detail") || "Unknown error" case status when 401 Teamtailor::UnauthorizedRequestError.new when 406 Teamtailor::InvalidApiVersionError.new() when 422 Teamtailor::UnprocessableEntityError.new() when 429 RateLimitError.new when 400..499 ClientError.new() when 500..599 ServerError.new() else UnknownResponseError.new("Unexpected error (status: #{status})") end end |
.parse_body(body) ⇒ Object
28 29 30 31 32 |
# File 'lib/teamtailor/error.rb', line 28 def self.parse_body(body) JSON.parse(body) rescue JSON::ParserError {} end |