New Microsoft Word Document (3)
New Microsoft Word Document (3)
@ExceptionHandler(ValidationException.class)
public ResponseEntity<ApiResponse<Void>>
handleValidationException(ValidationException ex) {
ErrorDetails error = new
ErrorDetails("VALIDATION_FAILED", "Validation failed",
LocalDateTime.now().toString(),
ex.getValidationErrors());
return new ResponseEntity<>(new
ApiResponse<>(false, null, error),
HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ApiResponse<Void>>
handleGenericException(Exception ex) {
ErrorDetails error = new
ErrorDetails("INTERNAL_SERVER_ERROR", "An
unexpected error occurred",
LocalDateTime.now().toString(),
Collections.singletonList(ex.getMessage()));
return new ResponseEntity<>(new
ApiResponse<>(false, null, error),
HttpStatus.INTERNAL_SERVER_ERROR);
}
}
text