Exception: Teamtailor::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Teamtailor::Error
show all
- Defined in:
- lib/teamtailor/error.rb
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)
error_message = 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(error_message)
when 422
Teamtailor::UnprocessableEntityError.new(error_message)
when 429
RateLimitError.new
when 400..499
ClientError.new(error_message)
when 500..599
ServerError.new(error_message)
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
|