Skip to content

Conversation

@main24
Copy link
Member

@main24 main24 commented Aug 29, 2025

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

  • Raise error Vend::PaymentRequired on HTTP code 402 -- that's observable behaviour of Vend API;
  • Raise the default error Vend::HttpError on all HTTP codes (including 0) other than 200..299.

@main24 main24 requested review from a team and Copilot August 29, 2025 15:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PaymentRequired exception 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' }
Copy link

Copilot AI Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' }

Copilot uses AI. Check for mistakes.
@nattfodd nattfodd requested a review from a team August 29, 2025 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants