Skip to content

Commit

Permalink
Too big error message JabRef#4827
Browse files Browse the repository at this point in the history
  • Loading branch information
dpolishc committed May 12, 2019
1 parent 751c5b5 commit d249da1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/main/java/org/jabref/logic/shared/DBMSConnection.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package org.jabref.logic.shared;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;

import org.jabref.logic.l10n.Localization;
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.model.database.shared.DBMSType;
import org.jabref.model.database.shared.DatabaseConnection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;

public class DBMSConnection implements DatabaseConnection {

private static final Logger LOGGER = LoggerFactory.getLogger(DBMSConnection.class);
Expand All @@ -38,9 +37,12 @@ public DBMSConnection(DBMSConnectionProperties connectionProperties) throws SQLE
} catch (SQLException e) {
// Some systems like PostgreSQL retrieves 0 to every exception.
// Therefore a stable error determination is not possible.
LOGGER.error("Could not connect to database: " + e.getMessage() + " - Error code: " + e.getErrorCode());
String message = e.getMessage();
int endIndex = message.indexOf(".") != -1 ? message.indexOf(".") : message.length();
String errorMessagee = e.getSQLState().equals("01S00") ? message.substring(0, endIndex) : message;
LOGGER.error("Could not connect to database: " + message + " - Error code: " + e.getErrorCode());

throw e;
throw new SQLException(errorMessagee, e);
}
}

Expand Down

0 comments on commit d249da1

Please sign in to comment.