Skip to content

Commit 8bc5bca

Browse files
committed
Add error code for class not found exception in mysql connect result
1 parent 1f2aa40 commit 8bc5bca

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/link/mysql/MySQLConnectionUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class MySQLConnectionUtils {
2020
private static final String CONNECTION_ISSUE_MESSAGE = "%s Please follow https://docs.microsoft.com/en-us/azure/mysql/howto-manage-firewall-using-portal "
2121
+ "to create a firewall rule to unblock your local access.";
2222
private static final int CONNECTION_ERROR_CODE = 9000;
23+
private static final int CLASS_NOT_FOUND_ERROR_CODE = -1000;
24+
private static final int UNKNOWN_EXCEPTION_ERROR_CODE = -1;
2325

2426
public static boolean connect(String url, String username, String password) {
2527
try {
@@ -51,11 +53,12 @@ public static ConnectResult connectWithPing(String url, String username, String
5153
}
5254
pingCost = System.currentTimeMillis() - start;
5355
serverVersion = ((ConnectionImpl) connection).getServerVersion().toString();
54-
} catch (final ClassNotFoundException exception) {
55-
errorMessage = exception.getMessage();
5656
} catch (final SQLException exception) {
5757
errorCode = exception.getErrorCode();
5858
errorMessage = isConnectionIssue(exception) ? String.format(CONNECTION_ISSUE_MESSAGE, exception.getMessage()) : exception.getMessage();
59+
} catch (final ClassNotFoundException | RuntimeException exception) {
60+
errorCode = exception instanceof ClassNotFoundException ? CLASS_NOT_FOUND_ERROR_CODE : UNKNOWN_EXCEPTION_ERROR_CODE;
61+
errorMessage = exception.getMessage();
5962
}
6063
EventUtil.logEvent(EventType.info, ActionConstants.parse(ActionConstants.MySQL.TEST_CONNECTION).getServiceName(),
6164
ActionConstants.parse(ActionConstants.MySQL.TEST_CONNECTION).getOperationName(),

0 commit comments

Comments
 (0)