自定义 过分请求异常
This commit is contained in:
10
src/main/java/com/sqx/common/exception/CzgException.java
Normal file
10
src/main/java/com/sqx/common/exception/CzgException.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.sqx.common.exception;
|
||||
|
||||
/**
|
||||
* @author GYJoker
|
||||
*/
|
||||
public class CzgException extends Exception {
|
||||
public CzgException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
@@ -68,6 +70,12 @@ public class SqxExceptionHandler {
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@ExceptionHandler(CzgException.class)
|
||||
public ResponseEntity<Void> handleCzgException() {
|
||||
// 响应状态码为 444 表示无法处理的异常
|
||||
return new ResponseEntity<>(HttpStatus.TOO_MANY_REQUESTS);
|
||||
}
|
||||
|
||||
private void logErrorInfo(WebRequest webRequest) {
|
||||
if (webRequest instanceof ServletWebRequest) {
|
||||
ServletWebRequest servletWebRequest = (ServletWebRequest) webRequest;
|
||||
|
||||
Reference in New Issue
Block a user