From f94204466bdedf84120197443afdba794be83d0e Mon Sep 17 00:00:00 2001 From: peageon Date: Wed, 15 May 2024 23:14:23 +0900 Subject: [PATCH] feat: create global exception handler --- .../backend/GlobalExceptionHandler.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/com/runningmate/backend/GlobalExceptionHandler.java diff --git a/src/main/java/com/runningmate/backend/GlobalExceptionHandler.java b/src/main/java/com/runningmate/backend/GlobalExceptionHandler.java new file mode 100644 index 0000000..44ab863 --- /dev/null +++ b/src/main/java/com/runningmate/backend/GlobalExceptionHandler.java @@ -0,0 +1,19 @@ +package com.runningmate.backend; + +import com.runningmate.backend.member.exception.FieldExistsException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import java.util.List; +import java.util.Map; + +@RestControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(FieldExistsException.class) + public ResponseEntity>> handleFieldExistsException(FieldExistsException fe) { + return ResponseEntity.status(HttpStatus.CONFLICT).body(Map.of("exists", fe.getExists())); + } +}