This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package com.example.nto.Exception;
|
||||
|
||||
public class BookingConflictException extends RuntimeException {
|
||||
public BookingConflictException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.nto.Exception;
|
||||
|
||||
public class EmployeeNotFoundException extends RuntimeException {
|
||||
public EmployeeNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.example.nto.Exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(EmployeeNotFoundException.class)
|
||||
public ResponseEntity<String> EmployeeNotFoundException(EmployeeNotFoundException ex) {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(PlaceNotFoundException.class)
|
||||
public ResponseEntity<String> PlaceNotFoundException(PlaceNotFoundException ex) {
|
||||
return ResponseEntity.badRequest().body("Что-то пошло не так");
|
||||
}
|
||||
|
||||
@ExceptionHandler(BookingConflictException.class)
|
||||
public ResponseEntity<String> BookingConflictException(BookingConflictException ex) {
|
||||
return ResponseEntity.status(HttpStatus.CONFLICT).body(ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<String> Exception(Exception ex) {
|
||||
return ResponseEntity.badRequest().body("Что-то пошло не так");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.nto.Exception;
|
||||
|
||||
public class PlaceNotFoundException extends RuntimeException {
|
||||
public PlaceNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user