Files
NTO-2025-Backend-TeamTask/src/main/java/com/example/nto/exception/handler/GlobalExceptionHandler.java
v3less11 d530e32e44 changes
2025-12-08 21:20:18 +03:00

30 lines
1.1 KiB
Java

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