From 1d2968468940848ab2e717ff9cf31696d6668803 Mon Sep 17 00:00:00 2001 From: heshunme Date: Tue, 2 Jul 2024 02:27:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=B1=80ExceptionHa?= =?UTF-8?q?ndle=E4=BB=A5=E6=9B=B4=E4=BC=98=E9=9B=85=E5=9C=B0=E5=A4=84?= =?UTF-8?q?=E7=90=86JwtValidationException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cmh/backend/Utils/GlobalExceptionHandler.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/org/cmh/backend/Utils/GlobalExceptionHandler.java diff --git a/src/main/java/org/cmh/backend/Utils/GlobalExceptionHandler.java b/src/main/java/org/cmh/backend/Utils/GlobalExceptionHandler.java new file mode 100644 index 0000000..b513f14 --- /dev/null +++ b/src/main/java/org/cmh/backend/Utils/GlobalExceptionHandler.java @@ -0,0 +1,15 @@ +package org.cmh.backend.Utils; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(JwtValidationException.class) + public ResponseEntity handleJwtInvalidException(JwtValidationException ex) { + return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + } +} \ No newline at end of file