This is an automated email from the ASF dual-hosted git repository.

menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new f08b098  Refactor SQLException handling in PostgreSQL Proxy (#10282)
f08b098 is described below

commit f08b09816901de8ea82f789b15328f5849db12c7
Author: 吴伟杰 <[email protected]>
AuthorDate: Sat May 8 14:51:33 2021 +0800

    Refactor SQLException handling in PostgreSQL Proxy (#10282)
---
 .../frontend/postgresql/err/PostgreSQLErrPacketFactory.java    | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java
index 5be6ee3..1e01131 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java
@@ -48,8 +48,7 @@ public final class PostgreSQLErrPacketFactory {
             return createErrorResponsePacket(((PSQLException) 
cause).getServerErrorMessage());
         }
         if (cause instanceof SQLException) {
-            // TODO consider what severity to use
-            return 
PostgreSQLErrorResponsePacket.newBuilder(PostgreSQLMessageSeverityLevel.ERROR, 
((SQLException) cause).getSQLState(), cause.getMessage()).build();
+            return createErrorResponsePacket((SQLException) cause);
         }
         if (cause instanceof InvalidAuthorizationSpecificationException) {
             return 
PostgreSQLErrorResponsePacket.newBuilder(PostgreSQLMessageSeverityLevel.FATAL, 
PostgreSQLErrorCode.INVALID_AUTHORIZATION_SPECIFICATION, 
cause.getMessage()).build();
@@ -65,6 +64,13 @@ public final class PostgreSQLErrPacketFactory {
         return createErrorResponsePacketForUnknownException(cause);
     }
     
+    private static PostgreSQLErrorResponsePacket 
createErrorResponsePacket(final SQLException cause) {
+        // TODO consider what severity to use
+        String sqlState = Strings.isNullOrEmpty(cause.getSQLState()) ? 
PostgreSQLErrorCode.SYSTEM_ERROR.getErrorCode() : cause.getSQLState();
+        String message = Strings.isNullOrEmpty(cause.getMessage()) ? 
cause.toString() : cause.getMessage();
+        return 
PostgreSQLErrorResponsePacket.newBuilder(PostgreSQLMessageSeverityLevel.ERROR, 
sqlState, message).build();
+    }
+    
     private static PostgreSQLErrorResponsePacket 
createErrorResponsePacket(final ServerErrorMessage serverErrorMessage) {
         return 
PostgreSQLErrorResponsePacket.newBuilder(PostgreSQLMessageSeverityLevel.valueOf(serverErrorMessage.getSeverity()),
 serverErrorMessage.getSQLState(), serverErrorMessage.getMessage())
                 
.detail(serverErrorMessage.getDetail()).hint(serverErrorMessage.getHint()).position(serverErrorMessage.getPosition())

Reply via email to