init
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.dken.userservice.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(DefaultException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public Map<String, String> handleDefaultException(DefaultException ex) {
|
||||
return Map.of("message", ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(InvalidUserIdException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public Map<String, String> handleInvalidId(InvalidUserIdException ex) {
|
||||
return Map.of("message", ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(UserNotFoundException.class)
|
||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
public Map<String, String> handleNotFound(UserNotFoundException ex) {
|
||||
return Map.of("message", ex.getMessage());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user