Skip to content

Commit

Permalink
Map 429 api error to exception (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
DyegoCosta authored Aug 8, 2024
1 parent 74df9a4 commit 6d1ccac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/castle/core/process_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module ProcessResponse
401 => Castle::UnauthorizedError,
403 => Castle::ForbiddenError,
404 => Castle::NotFoundError,
419 => Castle::UserUnauthorizedError
419 => Castle::UserUnauthorizedError,
429 => Castle::TooManyRequestsError
}.freeze

INVALID_REQUEST_TOKEN = 'invalid_request_token'
Expand Down
4 changes: 4 additions & 0 deletions lib/castle/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class InvalidRequestTokenError < Castle::ApiError
class UnauthorizedError < Castle::ApiError
end

# api error too many requests 429
class TooManyRequestsError < Castle::ApiError
end

# all internal server errors
class InternalServerError < Castle::ApiError
end
Expand Down
1 change: 1 addition & 0 deletions spec/lib/castle/core/process_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
it_behaves_like 'response_failed', '404', Castle::NotFoundError
it_behaves_like 'response_failed', '419', Castle::UserUnauthorizedError
it_behaves_like 'response_failed', '422', Castle::InvalidParametersError
it_behaves_like 'response_failed', '429', Castle::TooManyRequestsError
it_behaves_like 'response_failed', '499', Castle::ApiError
it_behaves_like 'response_failed', '500', Castle::InternalServerError
end
Expand Down

0 comments on commit 6d1ccac

Please sign in to comment.