Skip to content

Commit

Permalink
ResultHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
javahongxi committed Sep 10, 2020
1 parent f3b95e4 commit 23ea707
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@
*/
public class ResultHelper {

public static Result newSuccessResult() {
return newResult(true);
}

public static <T> 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);
}
Expand All @@ -31,8 +35,4 @@ public static Result newResult(boolean success, String message) {
}
}

public static Result newResult(int code, String message) {
return new Result(code, message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -35,6 +35,6 @@ public Result handleException(HttpServletRequest request, Exception e) throws Ex
throw e;
}
log.error("exception handled, request:{}", request.getRequestURI(), e);
return ResultHelper.newResult(500, e.getMessage());
return ResultHelper.newErrorResult(500, e.getMessage());
}
}

0 comments on commit 23ea707

Please sign in to comment.