forked from Olympic/NTO-2025-Backend-TeamTask
changes
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user