Add results exception return code.

pull/161/head
chen.ma 3 years ago
parent 7d6b23f947
commit cd3a790a8b

@ -1,6 +1,6 @@
package com.github.dynamic.threadpool.common.web.base; package com.github.dynamic.threadpool.common.web.base;
import com.github.dynamic.threadpool.common.web.exception.ErrorCode; import com.github.dynamic.threadpool.common.web.exception.ErrorCodeEnum;
import com.github.dynamic.threadpool.common.web.exception.ServiceException; import com.github.dynamic.threadpool.common.web.exception.ServiceException;
/** /**
@ -23,7 +23,7 @@ public final class Results {
} }
public static <T> Result<T> failure(ServiceException serviceException) { public static <T> Result<T> failure(ServiceException serviceException) {
return new Result<T>().setCode(ErrorCode.SERVICE_ERROR.getCode()) return new Result<T>().setCode(ErrorCodeEnum.SERVICE_ERROR.getCode())
.setMessage(serviceException.getMessage()); .setMessage(serviceException.getMessage());
} }
@ -33,4 +33,10 @@ public final class Results {
.setMessage(message); .setMessage(message);
} }
public static <T> Result<T> failure(ErrorCodeEnum errorCode) {
return new Result<T>()
.setCode(errorCode.getCode())
.setMessage(errorCode.getMessage());
}
} }

@ -6,7 +6,7 @@ package com.github.dynamic.threadpool.common.web.exception;
* @author chen.ma * @author chen.ma
* @date 2021/3/19 16:07 * @date 2021/3/19 16:07
*/ */
public enum ErrorCode { public enum ErrorCodeEnum {
UNKNOWN_ERROR { UNKNOWN_ERROR {
@Override @Override
@ -42,6 +42,18 @@ public enum ErrorCode {
public String getMessage() { public String getMessage() {
return "服务异常"; return "服务异常";
} }
},
NOT_FOUND {
@Override
public String getCode() {
return "404";
}
@Override
public String getMessage() {
return "未找到异常";
}
}; };
public abstract String getCode(); public abstract String getCode();
Loading…
Cancel
Save