mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-08-02 21:50:43 +08:00
exception optimization
This commit is contained in:
@ -31,4 +31,9 @@ public class DataSourceConnect {
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* error detail
|
||||
*/
|
||||
private String errorDetail;
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package ai.chat2db.spi.util;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* exception utils
|
||||
*/
|
||||
public class ExceptionUtils {
|
||||
|
||||
/**
|
||||
* print stack trace
|
||||
*
|
||||
* @param throwable
|
||||
* @return
|
||||
*/
|
||||
public static String getErrorInfoFromException(Throwable throwable) {
|
||||
String errorDetail = "";
|
||||
try {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
throwable.printStackTrace(pw);
|
||||
errorDetail = "\r\n" + sw.toString() + "\r\n";
|
||||
sw.close();
|
||||
pw.close();
|
||||
} catch (Exception e2) {
|
||||
return "ErrorInfoFromException";
|
||||
}
|
||||
return errorDetail;
|
||||
}
|
||||
}
|
@ -223,6 +223,7 @@ public class JdbcUtils {
|
||||
t = t.getCause();
|
||||
}
|
||||
dataSourceConnect.setMessage(t.getMessage());
|
||||
dataSourceConnect.setErrorDetail(ExceptionUtils.getErrorInfoFromException(t));
|
||||
return dataSourceConnect;
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
|
Reference in New Issue
Block a user