package com.estate.expert.admin.utils;
|
import org.springframework.http.HttpStatus;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
/**
|
* 错误控制器
|
*/
|
@ControllerAdvice
|
public class ErrorController {
|
|
/**
|
* 处理HttpMessageNotReadableException异常
|
* @param exception 异常
|
* @param request 请求
|
* @return 响应
|
*/
|
@ExceptionHandler(HttpMessageNotReadableException.class)
|
public ResponseEntity<String> handleException(HttpMessageNotReadableException exception, HttpServletRequest request) {
|
return new ResponseEntity<>(exception.getLocalizedMessage(), HttpStatus.BAD_REQUEST);
|
}
|
}
|