42 lines
1.7 KiB
Java
42 lines
1.7 KiB
Java
package com.example.nto.exception.handler;
|
|
|
|
import com.example.nto.exception.*;
|
|
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(EmployeeNotFoundException.class)
|
|
public ResponseEntity<String> handleEmployeeNotFoundException(EmployeeNotFoundException e) {
|
|
return new ResponseEntity<>(e.getMessage(), HttpStatus.UNAUTHORIZED);
|
|
}
|
|
|
|
@ExceptionHandler(BookingAlreadyExistsException.class)
|
|
public ResponseEntity<String> handleBookingAlreadyExistsException(BookingAlreadyExistsException e) {
|
|
return new ResponseEntity<>(e.getMessage(), HttpStatus.CONFLICT);
|
|
}
|
|
|
|
@ExceptionHandler(PlaceNotFoundException.class)
|
|
public ResponseEntity<String> handlePlaceNotFoundException(PlaceNotFoundException e) {
|
|
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
@ExceptionHandler(EmployeeAlreadyExistsException.class)
|
|
public ResponseEntity<String> handleEmployeeAlreadyExistsException(EmployeeAlreadyExistsException e) {
|
|
return new ResponseEntity<>(e.getMessage(), HttpStatus.CONFLICT);
|
|
}
|
|
|
|
@ExceptionHandler(NoSuchUsernameException.class)
|
|
public ResponseEntity<String> handleNoSuchUsernameException(NoSuchUsernameException e) {
|
|
return new ResponseEntity<>(e.getMessage(), HttpStatus.CONFLICT);
|
|
}
|
|
|
|
@ExceptionHandler(Exception.class)
|
|
public ResponseEntity<String> handleGenericException(Exception e) {
|
|
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
}
|