瀏覽代碼

Handle too many requests error

Daniel Bohry 1 年之前
父節點
當前提交
b4b677f58b
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      src/main/java/com/danielbohry/stocks/controller/GlobalExceptionHandler.java

+ 6 - 1
src/main/java/com/danielbohry/stocks/controller/GlobalExceptionHandler.java

@@ -13,8 +13,13 @@ import org.springframework.web.context.request.WebRequest;
 public class GlobalExceptionHandler {
 
     @ExceptionHandler(FeignException.NotFound.class)
-    public ResponseEntity<Error> handleFeignStatusException(FeignException e, WebRequest request) {
+    public ResponseEntity<Error> handleNotFoundException(FeignException e, WebRequest request) {
         return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new Error(e.getMessage()));
     }
 
+    @ExceptionHandler(FeignException.TooManyRequests.class)
+    public ResponseEntity<Error> handleTooManyRequestsException(FeignException e, WebRequest request) {
+        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new Error(e.getMessage()));
+    }
+
 }