geniusjun opened a new pull request, #10299:
URL: https://github.com/apache/gravitino/pull/10299
## What changes were proposed in this pull request?
This PR fixes incorrect HTTP semantics in POST
/metalakes/{metalake}/catalogs/testConnection error handling.
- Updated ExceptionHandlers.handleTestConnectionException(Exception e) to
return status-aware Utils responses instead of always returning 200 OK.
- Replaced manual ErrorResponse + Response.Status.OK building with:
- IllegalArgumentException -> Utils.illegalArguments(...) (400)
- NotFoundException -> Utils.notFound(...) (404)
- AlreadyExistsException -> Utils.alreadyExists(...) (409)
- NotInUseException -> Utils.notInUse(...) (409)
- ConnectionFailedException -> Utils.connectionFailed(...) (502)
- fallback -> Utils.internalError(...) (500)
- Added
TestExceptionHandlers.testHandleTestConnectionExceptionShouldReturnErrorStatus
to verify status mapping.
- Extended TestCatalogOperations.testConnection to verify API-level behavior
for IllegalArgumentException (400) and error body code/type.
## Why are the changes needed?
testConnection could return HTTP 200 OK even when validation/connection
errors occurred.
This caused clients to treat failed checks as successful at the HTTP layer.
The change aligns status codes with actual outcomes while preserving
existing error response body format.
Fix: #10126
## Does this PR introduce any user-facing change?
Yes.
- For POST /metalakes/{metalake}/catalogs/testConnection, error cases no
longer return 200 OK.
- Users/clients will now receive proper non-200 statuses
(400/404/409/502/500) depending on exception type.
- Error payload format is unchanged.
## How was this patch tested?
- Added/updated unit tests:
-
server/src/test/java/org/apache/gravitino/server/web/rest/TestExceptionHandlers.java
-
server/src/test/java/org/apache/gravitino/server/web/rest/TestCatalogOperations.java
- Ran:
- ./gradlew :server:test --tests
org.apache.gravitino.server.web.rest.TestExceptionHandlers --tests
org.apache.gravitino.server.web.rest.TestCatalogOperations -PskipITs
- Result: BUILD SUCCESSFUL (JDK 17).
--
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]