justinmclean opened a new issue, #10126:
URL: https://github.com/apache/gravitino/issues/10126
### What would you like to be improved?
POST /metalakes/{metalake}/catalogs/testConnection returns HTTP 200 OK even
when connection validation fails with known errors. In
ExceptionHandlers.handleTestConnectionException(...), the code builds an
ErrorResponse for these failures but still sends Response.Status.OK. This makes
real failures look successful at the HTTP level.
### How should we improve?
Update handleTestConnectionException(Exception e) in
gravitino/server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java
to return proper non-200 statuses per exception type, reusing existing helpers:
IllegalArgumentException -> Utils.illegalArguments(...) (400)
NotFoundException -> Utils.notFound(...) (404)
AlreadyExistsException -> Utils.alreadyExists(...) (409)
fallback -> Utils.internalError(...) (500)
etc etc
This keeps the existing error body format while fixing HTTP semantics.
Here a unit text to help:
```
public class TestExceptionHandlers {
@Test
public void testGetErrorMsg() {
Exception e1 = new Exception("test1");
Exception e2 = new Exception("test2", e1);
Exception e3 = new Exception(e1);
Exception e4 = new Exception();
Exception e5 = new Exception(e2);
Exception e6 = null;
String msg1 = ExceptionHandlers.BaseExceptionHandler.getErrorMsg(e1);
Assertions.assertEquals("test1", msg1);
String msg2 = ExceptionHandlers.BaseExceptionHandler.getErrorMsg(e2);
Assertions.assertEquals("test2", msg2);
String msg3 = ExceptionHandlers.BaseExceptionHandler.getErrorMsg(e3);
Assertions.assertEquals("test1", msg3);
String msg4 = ExceptionHandlers.BaseExceptionHandler.getErrorMsg(e4);
Assertions.assertEquals("", msg4);
String msg5 = ExceptionHandlers.BaseExceptionHandler.getErrorMsg(e5);
Assertions.assertEquals("test2", msg5);
String msg6 = ExceptionHandlers.BaseExceptionHandler.getErrorMsg(e6);
Assertions.assertEquals("", msg6);
}
@Test
public void testHandleTestConnectionExceptionShouldReturnErrorStatus() {
Response response =
ExceptionHandlers.handleTestConnectionException(
new IllegalArgumentException("invalid properties"));
Assertions.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
}
}
```
--
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]