Skip to content

fix: do not raise exception on 3xx responses in parse_response#173

Merged
armando-rodriguez-cko merged 2 commits into
masterfrom
fix/155-parse-response-3xx-status
May 26, 2026
Merged

fix: do not raise exception on 3xx responses in parse_response#173
armando-rodriguez-cko merged 2 commits into
masterfrom
fix/155-parse-response-3xx-status

Conversation

@armando-rodriguez-cko
Copy link
Copy Markdown
Contributor

What

parse_response was raising CheckoutApiException for any status code >= 300, incorrectly treating 3xx redirect responses as errors. The GET /reports/{reportId}/files/{fileId} endpoint returns 302 Found with a Location header, which was being raised as an exception.

Changes

  • lib/checkout_sdk/api_client.rb — change error boundary from >= 300 to >= 400 so 3xx responses are treated as successful
  • spec/checkout_sdk/api_client_spec.rb — add two tests covering 302 redirect: one asserting no exception is raised, one asserting http_metadata.status_code is preserved

Root cause

The condition response.status >= 300 was too broad. 3xx responses are valid success responses for certain endpoints (e.g. report file downloads). Fix proposed in the original issue: change to response.status >= 400.

Closes #155

Testing

  • All existing tests pass (12 examples, 0 failures)
  • New RSpec tests added for 302 redirect handling
  • No orphaned files

…#155)

Change the error boundary from >= 300 to >= 400 so that 3xx responses
(e.g. 302 returned by getReportFile) are treated as successful and not
raised as CheckoutApiException.

Add RSpec tests covering 302 redirect responses to prevent regression.
@sonarqubecloud
Copy link
Copy Markdown

@armando-rodriguez-cko armando-rodriguez-cko merged commit 1de9611 into master May 26, 2026
5 checks passed
@armando-rodriguez-cko armando-rodriguez-cko deleted the fix/155-parse-response-3xx-status branch May 26, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Exception is raised in parse_response if status code is 3xx

2 participants