Skip to content

Commit

Permalink
update exceptionAdvice
Browse files Browse the repository at this point in the history
  • Loading branch information
pingxingshikong committed Jun 16, 2021
1 parent 638c794 commit 0631085
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public ResultMap ConnectException(ConnectException e){
*/
@ExceptionHandler(ConstraintViolationException.class)
public ResultMap ConstraintViolationException(ConstraintViolationException e){
log.warn(e.getMessage());
List<ConstraintViolation> errorInformation = new ArrayList<ConstraintViolation>(e.getConstraintViolations());
return ResultMap.builder().code(CodeConstant.VALITOR_ERROR_CODE)
.msg(errorInformation.get(0).getMessage());
Expand All @@ -83,6 +84,7 @@ public ResultMap ConstraintViolationException(ConstraintViolationException e){
*/
@ExceptionHandler(BindException.class)
public ResultMap BindException(BindException e){
log.warn(e.getMessage());
List<String> errorInformation = e.getBindingResult().getAllErrors()
.stream()
.map(ObjectError::getDefaultMessage)
Expand All @@ -100,6 +102,7 @@ public ResultMap BindException(BindException e){
*/
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResultMap MethodArgumentNotValidException(MethodArgumentNotValidException e){
log.warn(e.getMessage());
String msg = msgConvertor(((MethodArgumentNotValidException) e).getBindingResult());
return ResultMap.builder().code(CodeConstant.VALITOR_ERROR_CODE)
.msg(msg);
Expand Down Expand Up @@ -165,7 +168,8 @@ public ResultMap TaskMsgException(TaskMsgException e){
* @return
*/
@ExceptionHandler(HttpMessageNotReadableException.class)
public ResultMap HttpMessageNotReadableException(){
public ResultMap HttpMessageNotReadableException(HttpMessageNotReadableException e){
log.warn(e.getMessage());
return ResultMap.builder().code(CodeConstant.HTTP_MSG_PARSE_ERROR_CODE)
.msg(HttpMsgConstant.HTTP_MSG_PARSE_ERROR_CODE);
}
Expand All @@ -175,7 +179,8 @@ public ResultMap HttpMessageNotReadableException(){
* @return
*/
@ExceptionHandler(Exception.class)
public ResultMap Exception(){
public ResultMap Exception(Exception e){
log.warn(e.getMessage());
return ResultMap.builder().code(CodeConstant.HTTP_ERROR_CODE)
.msg(HttpMsgConstant.HTTP_ERROR_MESSAGE);
}
Expand Down

0 comments on commit 0631085

Please sign in to comment.