forked from Olympic/NTO-2025-Backend-TeamTask
30 lines
1.1 KiB
Java
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));
|
|
}
|
|
|
|
}
|