自定义 过分请求异常

This commit is contained in:
GYJ
2024-12-28 17:39:19 +08:00
parent 0f12ed5161
commit 3b5c8f0af4
4 changed files with 30 additions and 5 deletions

View File

@@ -0,0 +1,10 @@
package com.sqx.common.exception;
/**
* @author GYJoker
*/
public class CzgException extends Exception {
public CzgException(String message) {
super(message);
}
}

View File

@@ -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;