This commit is contained in:
v3less11
2025-12-08 21:20:18 +03:00
parent 83b3202ea2
commit d530e32e44
22 changed files with 395 additions and 9 deletions

View File

@@ -0,0 +1,29 @@
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));
}
}