diff --git a/whatsmars-common/src/main/java/org/hongxi/whatsmars/common/result/ResultHelper.java b/whatsmars-common/src/main/java/org/hongxi/whatsmars/common/result/ResultHelper.java index 569fb46c744456cace263eafafdfa40eaf85a381..a426cf76d6eacd839e89faed5659cc684710be64 100644 --- a/whatsmars-common/src/main/java/org/hongxi/whatsmars/common/result/ResultHelper.java +++ b/whatsmars-common/src/main/java/org/hongxi/whatsmars/common/result/ResultHelper.java @@ -5,20 +5,24 @@ package org.hongxi.whatsmars.common.result; */ public class ResultHelper { - public static Result newSuccessResult() { - return newResult(true); - } - public static Result newSuccessResult(T data) { Result result = newSuccessResult(); result.setData(data); return result; } + public static Result newErrorResult(int code, String message) { + return new Result(code, message); + } + public static Result newErrorResult() { return newResult(false); } + public static Result newSuccessResult() { + return newResult(true); + } + public static Result newResult(boolean success) { return newResult(success, null); } @@ -31,8 +35,4 @@ public class ResultHelper { } } - public static Result newResult(int code, String message) { - return new Result(code, message); - } - } diff --git a/whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/exception/DefaultExceptionHandler.java b/whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/exception/DefaultExceptionHandler.java index df436e5d640a4595f0ae5692e9cd7eb3c842aa19..36038e36f97473cd32d5b61bd31b8bd0b9764f54 100644 --- a/whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/exception/DefaultExceptionHandler.java +++ b/whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/exception/DefaultExceptionHandler.java @@ -24,7 +24,7 @@ public class DefaultExceptionHandler { @ResponseBody public Result handleLogicException(HttpServletRequest request, BusinessException e) { log.error("business exception handled, request:{}", request.getRequestURI(), e); - return ResultHelper.newResult(e.getCode(), e.getMsg()); + return ResultHelper.newErrorResult(e.getCode(), e.getMsg()); } @ResponseStatus(HttpStatus.OK) @@ -35,6 +35,6 @@ public class DefaultExceptionHandler { throw e; } log.error("exception handled, request:{}", request.getRequestURI(), e); - return ResultHelper.newResult(500, e.getMessage()); + return ResultHelper.newErrorResult(500, e.getMessage()); } }