Raise errors on all unsuccessful HTTP response codes#3
Open
Raise errors on all unsuccessful HTTP response codes#3
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR improves error handling for HTTP response codes by ensuring all unsuccessful status codes (outside 200-299) raise appropriate exceptions. Previously, only specific mapped error codes would raise exceptions, potentially causing parsing errors for unmapped unsuccessful responses.
- Adds
PaymentRequiredexception class for HTTP 402 responses - Changes logic to raise exceptions for all non-2xx status codes, including code 0
- Refactors error handling logic into separate helper methods for better maintainability
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/vend/exception.rb | Adds PaymentRequired exception class, updates error handling logic to catch all non-2xx codes, and refactors into helper methods |
| spec/vend/unit/exception_spec.rb | Comprehensive test updates covering successful responses, error code 0, unmapped error codes, and specific exception mappings |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| context 'when response code is mapped to a known exception class' do | ||
| let(:unknown_error_codes) { [*100..199] + [*300..599] - Vend::HttpErrors::ERRORS.keys } | ||
|
|
||
| let(:body) { 'Something web wrong' } |
There was a problem hiding this comment.
There's a typo in the error message. 'Something web wrong' should be 'Something went wrong'.
Suggested change
| let(:body) { 'Something web wrong' } | |
| let(:body) { 'Something went wrong' } |
nattfodd
approved these changes
Aug 29, 2025
sharshenov
approved these changes
Aug 29, 2025
yevgenko
approved these changes
Aug 29, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Currently not all unsuccessful HTTP response codes are treated as unsuccessful response.
That leads to an error on parsing response body later in the flow.
Solution
Vend::PaymentRequiredon HTTP code 402 -- that's observable behaviour of Vend API;Vend::HttpErroron all HTTP codes (including 0) other than 200..299.