laserninja commented on code in PR #10668:
URL: https://github.com/apache/gravitino/pull/10668#discussion_r3036459524
##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergExceptionMapper.java:
##########
@@ -68,9 +71,41 @@ public class IcebergExceptionMapper implements
ExceptionMapper<Exception> {
.put(CommitFailedException.class, 409)
.put(UnprocessableEntityException.class, 422)
.put(CommitStateUnknownException.class, 500)
+ .put(ServiceFailureException.class, 500)
.put(ServiceUnavailableException.class, 503)
.build();
+ /**
+ * Returns the HTTP status code for the given exception based on the Iceberg
REST spec.
+ *
+ * @param ex the exception
+ * @return the HTTP status code, defaulting to 500 for unmapped exceptions
+ */
+ public static int getErrorCode(Exception ex) {
+ return EXCEPTION_ERROR_CODES.getOrDefault(
+ ex.getClass(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ }
+
+ /**
+ * Converts a Gravitino or generic exception to the corresponding Iceberg
REST spec exception.
+ *
+ * @param e the original exception
+ * @return the equivalent Iceberg exception, or the original if already an
Iceberg exception
+ */
+ public static Exception convertToIcebergException(Exception e) {
+ String message = e.getMessage() != null ? e.getMessage() : "";
+ if (e instanceof UnauthorizedException) {
+ return new NotAuthorizedException("%s", message);
+ }
+ if (e instanceof org.apache.gravitino.exceptions.ForbiddenException) {
+ return new ForbiddenException("%s", message);
+ }
Review Comment:
`convertToIcebergException()` now explicitly converts
`IllegalArgumentException`, `ValidationException`,
`IllegalNameIdentifierException`, and `NamespaceNotEmptyException` to
`BadRequestException`
--
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]