package com.example.nto.exception.handler; import com.example.nto.exception.CodeIsNotExistException; import com.example.nto.exception.PlaceAlreadyBookedException; import com.example.nto.exception.UnknownException; 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(CodeIsNotExistException.class) public ResponseEntity handlerCodeIsNotFoundException(CodeIsNotExistException e){ return new ResponseEntity<>(e.getMessage(), HttpStatus.valueOf(401)); } @ExceptionHandler(UnknownException.class) public ResponseEntity handlerUnknownException(UnknownException e){ return new ResponseEntity<>(e.getMessage(), HttpStatus.valueOf(400)); } @ExceptionHandler(PlaceAlreadyBookedException.class) public ResponseEntity handlerPlaceAlreadyBookedException(UnknownException e){ return new ResponseEntity<>(e.getMessage(), HttpStatus.valueOf(409)); } }