This is an automated email from the ASF dual-hosted git repository.
yuqi1129 pushed a commit to branch branch-1.3
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/branch-1.3 by this push:
new 39029d019a [#14503] fix(server): return 502 for schema connection
failures on branch-1.3 (#14514)
39029d019a is described below
commit 39029d019a1d9ce25a76b1c69c03155a409b3798
Author: Qi Yu <[email protected]>
AuthorDate: Mon Nov 2 16:34:23 2026 +0800
[#14503] fix(server): return 502 for schema connection failures on
branch-1.3 (#14514)
### What changes were proposed in this pull request?
Backport the existing main-branch ConnectionFailedException-to-HTTP-502
fallback into the branch-1.3 base REST exception handler. Add schema
LIST/LOAD/CREATE/DROP coverage and non-connection status controls.
### Why are the changes needed?
On branch-1.3, schema connection failures fall through to generic HTTP
500 while table calls report 502. Main already contains the mapping
introduced with PR #11959; this change ports only the small fallback and
its regression coverage.
Fixes #14503
### Does this PR introduce _any_ user-facing change?
Schema source-connection failures now return 502 with
ConnectionFailedException. Existing validation, missing-schema,
permission and unexpected-error statuses remain 400, 404, 403 and 500.
### How was this patch tested?
All 473 branch-1.3 server module tests passed with -PskipITs. The added
schema connection regression failed with 500 before the fix and passes
for LIST/LOAD/CREATE/DROP afterward. Module Spotless passed.
---
.../server/web/rest/ExceptionHandlers.java | 6 ++++
.../server/web/rest/TestExceptionHandlers.java | 42 ++++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git
a/server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java
b/server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java
index 36791cf1ba..e5fad456e9 100644
---
a/server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java
+++
b/server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java
@@ -1123,6 +1123,12 @@ public class ExceptionHandlers {
String errorMsg =
getBaseErrorMsg(formattedObject, op.name(), formattedParent,
getErrorMsg(e));
+ // A source catalog connection failure is a downstream failure rather
than a server bug.
+ if (e instanceof ConnectionFailedException) {
+ LOG.warn(errorMsg, e);
+ return Utils.connectionFailed(errorMsg, e);
+ }
+
// Classify domain-specific UnsupportedOperationException subclasses
before the generic
// capability fallback below.
if (e instanceof UnmodifiableStatisticException) {
diff --git
a/server/src/test/java/org/apache/gravitino/server/web/rest/TestExceptionHandlers.java
b/server/src/test/java/org/apache/gravitino/server/web/rest/TestExceptionHandlers.java
index 60140578cf..f78d8f52e5 100644
---
a/server/src/test/java/org/apache/gravitino/server/web/rest/TestExceptionHandlers.java
+++
b/server/src/test/java/org/apache/gravitino/server/web/rest/TestExceptionHandlers.java
@@ -22,12 +22,54 @@ import java.util.List;
import javax.ws.rs.core.Response;
import org.apache.gravitino.dto.responses.ErrorConstants;
import org.apache.gravitino.dto.responses.ErrorResponse;
+import org.apache.gravitino.exceptions.ConnectionFailedException;
+import org.apache.gravitino.exceptions.ForbiddenException;
+import org.apache.gravitino.exceptions.NoSuchSchemaException;
import org.apache.gravitino.exceptions.UnmodifiableStatisticException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class TestExceptionHandlers {
+ @Test
+ void testSchemaConnectionFailuresReturnBadGateway() {
+ for (OperationType operation :
+ new OperationType[] {
+ OperationType.LIST, OperationType.LOAD, OperationType.CREATE,
OperationType.DROP
+ }) {
+ try (Response response =
+ ExceptionHandlers.handleSchemaException(
+ operation,
+ "schema",
+ "catalog",
+ new ConnectionFailedException("backend unavailable"))) {
+ Assertions.assertEquals(502, response.getStatus());
+ ErrorResponse error = (ErrorResponse) response.getEntity();
+ Assertions.assertEquals(ErrorConstants.CONNECTION_FAILED_CODE,
error.getCode());
+ Assertions.assertEquals("ConnectionFailedException", error.getType());
+ Assertions.assertTrue(error.getMessage().contains("backend
unavailable"));
+ }
+ }
+ }
+
+ @Test
+ void testSchemaNonConnectionErrorsKeepTheirStatuses() {
+ Exception[] failures = {
+ new IllegalArgumentException("bad input"),
+ new NoSuchSchemaException("missing"),
+ new ForbiddenException("denied"),
+ new RuntimeException("unexpected")
+ };
+ int[] statuses = {400, 404, 403, 500};
+ for (int i = 0; i < failures.length; i++) {
+ try (Response response =
+ ExceptionHandlers.handleSchemaException(
+ OperationType.LOAD, "schema", "catalog", failures[i])) {
+ Assertions.assertEquals(statuses[i], response.getStatus());
+ }
+ }
+ }
+
@Test
public void testGetErrorMsg() {
Exception e1 = new Exception("test1");