diff --git a/dynamic-threadpool-common/src/main/java/com/github/dynamic/threadpool/common/web/base/Results.java b/dynamic-threadpool-common/src/main/java/com/github/dynamic/threadpool/common/web/base/Results.java index 46a0dc70..5d015759 100644 --- a/dynamic-threadpool-common/src/main/java/com/github/dynamic/threadpool/common/web/base/Results.java +++ b/dynamic-threadpool-common/src/main/java/com/github/dynamic/threadpool/common/web/base/Results.java @@ -1,6 +1,6 @@ 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; /** @@ -23,7 +23,7 @@ public final class Results { } public static Result failure(ServiceException serviceException) { - return new Result().setCode(ErrorCode.SERVICE_ERROR.getCode()) + return new Result().setCode(ErrorCodeEnum.SERVICE_ERROR.getCode()) .setMessage(serviceException.getMessage()); } @@ -33,4 +33,10 @@ public final class Results { .setMessage(message); } + public static Result failure(ErrorCodeEnum errorCode) { + return new Result() + .setCode(errorCode.getCode()) + .setMessage(errorCode.getMessage()); + } + } diff --git a/dynamic-threadpool-common/src/main/java/com/github/dynamic/threadpool/common/web/exception/ErrorCode.java b/dynamic-threadpool-common/src/main/java/com/github/dynamic/threadpool/common/web/exception/ErrorCodeEnum.java similarity index 77% rename from dynamic-threadpool-common/src/main/java/com/github/dynamic/threadpool/common/web/exception/ErrorCode.java rename to dynamic-threadpool-common/src/main/java/com/github/dynamic/threadpool/common/web/exception/ErrorCodeEnum.java index 3c2736f4..23b713b5 100644 --- a/dynamic-threadpool-common/src/main/java/com/github/dynamic/threadpool/common/web/exception/ErrorCode.java +++ b/dynamic-threadpool-common/src/main/java/com/github/dynamic/threadpool/common/web/exception/ErrorCodeEnum.java @@ -6,7 +6,7 @@ package com.github.dynamic.threadpool.common.web.exception; * @author chen.ma * @date 2021/3/19 16:07 */ -public enum ErrorCode { +public enum ErrorCodeEnum { UNKNOWN_ERROR { @Override @@ -42,6 +42,18 @@ public enum ErrorCode { public String getMessage() { return "服务异常"; } + }, + + NOT_FOUND { + @Override + public String getCode() { + return "404"; + } + + @Override + public String getMessage() { + return "未找到异常"; + } }; public abstract String getCode();