异常模块进一步完善
This commit is contained in:
parent
7851e8af39
commit
8cecb69c01
@ -44,10 +44,21 @@ public class GlobalControllerExceptionHandler {
|
|||||||
|
|
||||||
//如果是自定义异常,则获取异常,返回自定义错误消息
|
//如果是自定义异常,则获取异常,返回自定义错误消息
|
||||||
if (e instanceof ServiceException) {
|
if (e instanceof ServiceException) {
|
||||||
ResultCode resultCode = ((ServiceException) e).getResultCode();
|
ServiceException serviceException = ((ServiceException) e);
|
||||||
|
ResultCode resultCode = serviceException.getResultCode();
|
||||||
|
|
||||||
|
Integer code = null;
|
||||||
|
String message = null;
|
||||||
|
|
||||||
if (resultCode != null) {
|
if (resultCode != null) {
|
||||||
return ResultUtil.error(resultCode.code(), resultCode.message());
|
code = resultCode.code();
|
||||||
|
message = resultCode.message();
|
||||||
}
|
}
|
||||||
|
//如果有扩展消息,则输出异常中,跟随补充异常
|
||||||
|
if (!serviceException.getMsg().equals(ServiceException.DEFAULT_MESSAGE)) {
|
||||||
|
message += ":" + serviceException.getMsg();
|
||||||
|
}
|
||||||
|
return ResultUtil.error(code, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
//默认错误消息
|
//默认错误消息
|
||||||
|
@ -4,13 +4,19 @@ import cn.lili.common.enums.ResultCode;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 全局业务异常类
|
||||||
|
*
|
||||||
* @author Chopper
|
* @author Chopper
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class ServiceException extends RuntimeException {
|
public class ServiceException extends RuntimeException {
|
||||||
|
|
||||||
private String msg;
|
public static String DEFAULT_MESSAGE = "网络错误,请稍后重试!";
|
||||||
|
|
||||||
|
//异常消息
|
||||||
|
private String msg = DEFAULT_MESSAGE;
|
||||||
|
|
||||||
|
//错误码
|
||||||
private ResultCode resultCode;
|
private ResultCode resultCode;
|
||||||
|
|
||||||
public ServiceException(String msg) {
|
public ServiceException(String msg) {
|
||||||
@ -19,8 +25,7 @@ public class ServiceException extends RuntimeException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ServiceException() {
|
public ServiceException() {
|
||||||
super("网络错误,请稍后重试!");
|
super();
|
||||||
this.msg = "网络错误,请稍后重试!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceException(ResultCode resultCode) {
|
public ServiceException(ResultCode resultCode) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user