优化 ExceptionUtil 工具类
1.增加私有构造函数,此工具类不能被实例化 2.优化 getRootErrorMessage() 方法逻辑,去除不必要判断
This commit is contained in:
parent
4f5bf990bf
commit
d1a8a58552
|
|
@ -11,6 +11,9 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
*/
|
*/
|
||||||
public class ExceptionUtil
|
public class ExceptionUtil
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private ExceptionUtil() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取exception的详细错误信息。
|
* 获取exception的详细错误信息。
|
||||||
*/
|
*/
|
||||||
|
|
@ -24,16 +27,10 @@ public class ExceptionUtil
|
||||||
public static String getRootErrorMessage(Exception e)
|
public static String getRootErrorMessage(Exception e)
|
||||||
{
|
{
|
||||||
Throwable root = ExceptionUtils.getRootCause(e);
|
Throwable root = ExceptionUtils.getRootCause(e);
|
||||||
root = (root == null ? e : root);
|
if (null == root)
|
||||||
if (root == null)
|
|
||||||
{
|
{
|
||||||
return "";
|
return StringUtils.EMPTY;
|
||||||
}
|
}
|
||||||
String msg = root.getMessage();
|
return StringUtils.defaultString(root.getMessage(), "null");
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return "null";
|
|
||||||
}
|
|
||||||
return StringUtils.defaultString(msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue