Skip to content

Handle all 2xx HTTP status codes as success - #2

Open
IFAKA wants to merge 1 commit into
romanmichaelpaolucci:mainfrom
IFAKA:fix/http-status-code-handling
Open

Handle all 2xx HTTP status codes as success#2
IFAKA wants to merge 1 commit into
romanmichaelpaolucci:mainfrom
IFAKA:fix/http-status-code-handling

Conversation

@IFAKA

@IFAKA IFAKA commented Dec 19, 2025

Copy link
Copy Markdown

Problem

The response handler only treats HTTP 200 as success:

if response.status_code == 200:
    return data

This means valid success responses like 201 (Created), 202 (Accepted), or 204 (No Content) are incorrectly treated as errors and raise APIError.

Fix

Use response.ok which returns True for any 2xx status code:

if response.ok:
    return data

Test

✓ 200 OK: Returned data correctly
✓ 201 Created: Returned data correctly
✓ 202 Accepted: Returned data correctly
✓ 204 No Content: Returned data correctly
✓ 400 Bad Request: Raised ValidationError correctly
✓ 401 Unauthorized: Raised AuthenticationError correctly
✓ 500 Server Error: Raised APIError correctly

==================================================
All tests passed!

Use response.ok instead of checking for status_code == 200
to properly handle 201, 202, 204, and other success codes.
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.

1 participant