flyrain commented on code in PR #1181:
URL: https://github.com/apache/polaris/pull/1181#discussion_r2008168726


##########
service/common/src/main/java/org/apache/polaris/service/exception/IcebergPersistenceExceptionMapper.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.service.exception;
+
+import jakarta.persistence.PersistenceException;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.ext.ExceptionMapper;
+import jakarta.ws.rs.ext.Provider;
+import org.apache.iceberg.rest.responses.ErrorResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.event.Level;
+
+
+@Provider
+public class IcebergPersistenceExceptionMapper
+    implements ExceptionMapper<PersistenceException> {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(IcebergPersistenceExceptionMapper.class);
+
+  @Override
+  public Response toResponse(PersistenceException exception) {
+    LOGGER.info("Full PersistenceException", exception);
+
+    ErrorResponse icebergErrorResponse =
+        ErrorResponse.builder()
+            
.responseCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())
+            .withType(exception.getClass().getSimpleName())

Review Comment:
   Looks like the class `IcebergExceptionMapper` also use the exception simple 
name as the type. I'm also not sure if any iceberg rest client relies on the 
type. I think the status code is good enough for most of use cases. Here is the 
error message definition in Iceberg REST spec. Looks like the type isn't tied 
to the status code. I think it's OK to use the exception name, but open to 
suggestions.
   
   ```
       ErrorModel:
         type: object
         description: JSON error payload returned in a response with further 
details on the error
         required:
           - message
           - type
           - code
         properties:
           message:
             type: string
             description: Human-readable error message
           type:
             type: string
             description: Internal type definition of the error
             example: NoSuchNamespaceException
           code:
             type: integer
             minimum: 400
             maximum: 600
             description: HTTP response code
             example: 404
   ```



-- 
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]

Reply via email to