dimas-b commented on code in PR #1181:
URL: https://github.com/apache/polaris/pull/1181#discussion_r2006801425


##########
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())
+            .withMessage(exception.getMessage())

Review Comment:
   The PR description mentions avoiding exposing internal database information 
in these errors, but will this message not contain database-specific 
information?
   
   Do you have an example exception and corresponding JSON error response?



##########
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:
   This "type" is supposed to be interpreted by Iceberg REST API clients, but I 
do not think "PersistenceException" is going to be very meaningful on the 
client side.



##########
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> {

Review Comment:
   I'm not sure creating a separate mapper just for `PersistenceException` is a 
good idea. `IcebergExceptionMapper` already deals with exception of multiple 
types. Could you integrate the new logic for `PersistenceException` there?



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