exception optimization

This commit is contained in:
robinji0
2023-07-08 15:23:04 +08:00
parent 16b02a2c34
commit 1ca149b5d2
19 changed files with 235 additions and 13 deletions

View File

@ -31,4 +31,9 @@ public class DataSourceConnect {
* 描述
*/
private String description;
/**
* error detail
*/
private String errorDetail;
}

View File

@ -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;
}
}

View File

@ -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) {