修改http状态码

This commit is contained in:
付庆吉
2021-01-14 15:22:36 +08:00
parent b765d068f8
commit 9d8bdc5cc8

View File

@ -72,7 +72,7 @@ public class BusinessExceptionHandlerAdvice {
* @return 响应 * @return 响应
*/ */
@ExceptionHandler(value = MethodArgumentNotValidException.class) @ExceptionHandler(value = MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.BAD_REQUEST)
public BaseResponse<String> handleInvalidMethodArgException(HttpServletRequest request, MethodArgumentNotValidException exception) { public BaseResponse<String> handleInvalidMethodArgException(HttpServletRequest request, MethodArgumentNotValidException exception) {
//堆栈信息转为字符串 //堆栈信息转为字符串
log.info(ExceptionUtil.stacktraceToString(exception)); log.info(ExceptionUtil.stacktraceToString(exception));
@ -102,7 +102,7 @@ public class BusinessExceptionHandlerAdvice {
* @return 响应 * @return 响应
*/ */
@ExceptionHandler(value = BindException.class) @ExceptionHandler(value = BindException.class)
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.BAD_REQUEST)
public BaseResponse<String> methodArgumentNotValidHandler( public BaseResponse<String> methodArgumentNotValidHandler(
HttpServletRequest request, BindException exception) { HttpServletRequest request, BindException exception) {
//按需重新封装需要返回的错误信息 //按需重新封装需要返回的错误信息
@ -147,7 +147,7 @@ public class BusinessExceptionHandlerAdvice {
* @return 响应 * @return 响应
*/ */
@ExceptionHandler(MissingServletRequestParameterException.class) @ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.BAD_REQUEST)
public BaseResponse<String> handleMissingParameterException(HttpServletRequest request, MissingServletRequestParameterException exception) { public BaseResponse<String> handleMissingParameterException(HttpServletRequest request, MissingServletRequestParameterException exception) {
Map<String, Object> body = new HashMap<>(); Map<String, Object> body = new HashMap<>();
body.put("errors", exception.getMessage()); body.put("errors", exception.getMessage());
@ -166,7 +166,7 @@ public class BusinessExceptionHandlerAdvice {
* @return 响应 * @return 响应
*/ */
@ExceptionHandler(DataAccessException.class) @ExceptionHandler(DataAccessException.class)
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.BAD_REQUEST)
public BaseResponse<String> handlerDataAccessException(HttpServletRequest request, DataAccessException exception) { public BaseResponse<String> handlerDataAccessException(HttpServletRequest request, DataAccessException exception) {
log.error(ExceptionUtil.stacktraceToString(exception)); log.error(ExceptionUtil.stacktraceToString(exception));
Map<String, Object> body = new HashMap<>(); Map<String, Object> body = new HashMap<>();
@ -184,7 +184,7 @@ public class BusinessExceptionHandlerAdvice {
* @return 响应 * @return 响应
*/ */
@ExceptionHandler(EmptyResultDataAccessException.class) @ExceptionHandler(EmptyResultDataAccessException.class)
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.BAD_REQUEST)
public BaseResponse<String> handleDataEmptyException(HttpServletRequest request, EmptyResultDataAccessException exception) { public BaseResponse<String> handleDataEmptyException(HttpServletRequest request, EmptyResultDataAccessException exception) {
Map<String, Object> body = new HashMap<>(); Map<String, Object> body = new HashMap<>();
body.put("errors", exception.getMessage()); body.put("errors", exception.getMessage());
@ -201,7 +201,7 @@ public class BusinessExceptionHandlerAdvice {
* @return 响应 * @return 响应
*/ */
@ExceptionHandler(DuplicateKeyException.class) @ExceptionHandler(DuplicateKeyException.class)
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.BAD_REQUEST)
public BaseResponse<String> handleDataDualException(HttpServletRequest request, DuplicateKeyException exception) { public BaseResponse<String> handleDataDualException(HttpServletRequest request, DuplicateKeyException exception) {
Map<String, Object> body = new HashMap<>(); Map<String, Object> body = new HashMap<>();
body.put("errors", exception.getMessage()); body.put("errors", exception.getMessage());
@ -218,7 +218,7 @@ public class BusinessExceptionHandlerAdvice {
* @return 响应 * @return 响应
*/ */
@ExceptionHandler(MethodArgumentTypeMismatchException.class) @ExceptionHandler(MethodArgumentTypeMismatchException.class)
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.BAD_REQUEST)
public BaseResponse<String> handleMethodArgumentTypeException(HttpServletRequest request, MethodArgumentTypeMismatchException exception) { public BaseResponse<String> handleMethodArgumentTypeException(HttpServletRequest request, MethodArgumentTypeMismatchException exception) {
Map<String, Object> body = new HashMap<>(); Map<String, Object> body = new HashMap<>();
body.put("errors", exception.getMessage()); body.put("errors", exception.getMessage());