package com.example.nto; import com.example.nto.exception.AlreadyBookedException; import com.example.nto.exception.CodeNotFoundException; import com.example.nto.exception.InvalidRequestException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; @ControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(InvalidRequestException.class) public ResponseEntity handleInvalidRequest(InvalidRequestException ex) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ex.getMessage()); } @ExceptionHandler(CodeNotFoundException.class) public ResponseEntity handleCodeNotFound(CodeNotFoundException ex) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ex.getMessage()); } @ExceptionHandler(AlreadyBookedException.class) public ResponseEntity handleAlreadyBooked(AlreadyBookedException ex) { return ResponseEntity.status(HttpStatus.CONFLICT).body(ex.getMessage()); } // Обработка ошибок парсинга JSON @ExceptionHandler(HttpMessageNotReadableException.class) public ResponseEntity handleJsonParseError(HttpMessageNotReadableException ex) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("что-то пошло не так"); } }