Skip to content

Commit

Permalink
feat: create global exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
peageon committed May 15, 2024
1 parent d7db3cf commit f942044
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/com/runningmate/backend/GlobalExceptionHandler.java
Original file line number Diff line number Diff line change
@@ -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<Map<String, List<String>>> handleFieldExistsException(FieldExistsException fe) {
return ResponseEntity.status(HttpStatus.CONFLICT).body(Map.of("exists", fe.getExists()));
}
}

0 comments on commit f942044

Please sign in to comment.