This commit is contained in:
fit2-zhao 2021-02-05 16:38:24 +08:00
commit 61992c14d5
1 changed files with 7 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
@RestControllerAdvice @RestControllerAdvice
@ -30,6 +31,12 @@ public class RestControllerExceptionHandler {
} }
@ExceptionHandler(SQLException.class)
public ResultHolder sqlExceptionHandler(HttpServletRequest request, HttpServletResponse response, MSException e) {
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return ResultHolder.error("SQL error happened, please check logs.");
}
@ExceptionHandler(MSException.class) @ExceptionHandler(MSException.class)
public ResultHolder msExceptionHandler(HttpServletRequest request, HttpServletResponse response, MSException e) { public ResultHolder msExceptionHandler(HttpServletRequest request, HttpServletResponse response, MSException e) {
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());