From cd3a790a8be53dea89fc0d2a2125242b4c29db03 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Sat, 14 Aug 2021 20:26:51 +0800 Subject: [PATCH] Add results exception return code. --- .../threadpool/common/web/base/Results.java | 10 ++++++++-- .../{ErrorCode.java => ErrorCodeEnum.java} | 14 +++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) rename dynamic-threadpool-common/src/main/java/com/github/dynamic/threadpool/common/web/exception/{ErrorCode.java => ErrorCodeEnum.java} (77%) 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();