Akash3121 opened a new pull request, #10029:
URL: https://github.com/apache/paimon/pull/10029
### Purpose
Fix PyPaimon REST error handling when a valid error response contains a
message but omits the optional application-level `code` field.
In this situation, PyPaimon previously ignored the HTTP response status and
raised a generic `RESTException`. The client now falls back to the HTTP status
so that callers receive the appropriate typed exception.
Closes #9983.
#### Background
A REST server may return an error body such as:
```json
{
"message": "missing",
"resourceType": "TABLE",
"resourceName": "db.t"
}
```
The body is valid and contains useful resource information, but it does not
contain an application-level code .
The HTTP response status still identifies the error—for example, 404 Not
Found —and should be used when the body does not provide its own code.
#### Behavior before and after
| Response | Previous behavior | New behavior |
|----------|-------------------|--------------|
| HTTP 404, JSON code omitted | Generic `RESTException` |
`NoSuchResourceException` |
| HTTP 409, JSON code omitted | Generic `RESTException` |
`AlreadyExistsException` |
| HTTP 503, JSON code omitted | Generic `RESTException` |
`ServiceUnavailableException` |
| JSON contains an explicit code | Uses JSON code | Unchanged |
| JSON contains explicit code `0` | Could fall back through a truthiness
check | Preserves `0` |
| Invalid JSON or empty body | Uses HTTP status | Unchanged |
### Tests
Added regression coverage for:
- valid error JSON without code for HTTP 404;
- valid error JSON without code for HTTP 409;
- valid error JSON without code for HTTP 503;
- preservation of an explicitly supplied zero code;
- end-to-end _execute_request mapping to:
- NoSuchResourceException ;
- AlreadyExistsException ;
- ServiceUnavailableException .
The focused REST client and catalog exception tests were run with:
python -m pytest \
paimon-python/pypaimon/tests/rest/client_test.py \
paimon-python/pypaimon/tests/api/test_rest_catalog_create_partitions.py \
-q
Result: 14 passed
The modified files also passed the configured Python style checks and Python
bytecode compilation.
#### Changelog - Bug fix
- PyPaimon REST responses that omit the optional application error code now
fall back to the HTTP response status.
- HTTP 404, 409, and 503 responses now produce their expected typed
exceptions instead of a generic RESTException .
#### Notes for reviewers
1. The fallback uses is None , not a truthiness check, so an explicit code
of 0 is preserved.
2. The response message and resource metadata remain unchanged when only
the code is missing.
3. Error bodies with an explicit application-level code continue to take
precedence over the HTTP status.
4. Invalid JSON, empty bodies, and parsed responses without a message
retain their existing fallback behavior.
5. The change is intentionally limited to error-response normalization and
focused regression tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]