| | |
| | | package com.moral.api.exception; |
| | | |
| | | import com.alibaba.druid.wall.violation.ErrorCode; |
| | | import com.moral.api.utils.StringUtils; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | | import com.moral.exception.TokenException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.support.DefaultMessageSourceResolvable; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.validation.FieldError; |
| | | import org.springframework.web.bind.MethodArgumentNotValidException; |
| | | import org.springframework.web.bind.annotation.ControllerAdvice; |
| | | import org.springframework.web.bind.annotation.ExceptionHandler; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.ResponseStatus; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | @ControllerAdvice |
| | |
| | | @ResponseBody |
| | | @ResponseStatus(HttpStatus.OK) |
| | | public ResultMessage handleUserNotExistException(BusinessException ex) { |
| | | return ResultMessage.fail(ResponseCodeEnum.FAIL.getCode(), "请求用户数据失败"); |
| | | return ResultMessage.fail(ResponseCodeEnum.FAIL.getCode(), ex.getMsg()); |
| | | } |
| | | |
| | | @ExceptionHandler |
| | | public ResultMessage exceptionHandler(MethodArgumentNotValidException e){ |
| | | List<String> collect = e.getBindingResult().getFieldErrors().stream().map(DefaultMessageSourceResolvable::getDefaultMessage) |
| | | .collect(Collectors.toList()); |
| | | return ResultMessage.fail(ResponseCodeEnum.FAIL.getCode(), StringUtils.join(collect, ",")); |
| | | } |
| | | |
| | | /** |