Abyss-lord commented on code in PR #8513:
URL: https://github.com/apache/gravitino/pull/8513#discussion_r2338350729


##########
catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/converter/PostgreSqlExceptionConverter.java:
##########
@@ -44,8 +44,12 @@ public GravitinoRuntimeException 
toGravitinoException(SQLException se) {
           return new NoSuchSchemaException(se.getMessage(), se);
         case "42P01":
           return new NoSuchTableException(se.getMessage(), se);
-        default:
+        default: {
+          if (se.getSQLState().startsWith("08")) {
+            return new ConnectionFailedException(se.getMessage(), se);
+          }
           return new GravitinoRuntimeException(se.getMessage(), se);
+        }

Review Comment:
   It would be better not to hardcode SQLState strings like "42P04" or "42P07" 
directly in the switch block. I suggest extracting these codes into a dedicated 
constants class (e.g. PostgresErrorCodes) or an enum or a static variable. That 
way, we can replace:
   ```java
   case "42P07":
       return new TableAlreadyExistsException(se.getMessage(), se);
   ```
   with something like:
   ```java
   case PostgresErrorCodes.DUPLICATE_TABLE:
       return new TableAlreadyExistsException(se.getMessage(), se);
   ```
   Meanwhile, you can change other variables. e.g.
   ```java
   private static final String DUPLICATE_DATABASE = "42P04";
   private blic static final String DUPLICATE_SCHEMA = "42P06";
   private static final String DUPLICATE_TABLE = "42P07";
   private static final String INVALID_SCHEMA_NAME = "3D000";
   private static final String INVALID_SCHEMA = "3F000";
   private static final String UNDEFINED_TABLE = "42P01";
   ```



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