我正在尝试将存储库异常映射到服务异常。这样的方法好吗?
@Override
public CompletableFuture<Void> delete(String id, Map<String, String> headers) {
CompletableFuture<Void> future = repository.delete(id, headers);
return future.handle((aVoid, throwable) -> {
if (throwable != null) {
Throwable cause = throwable.getCause();
if (DbExcUtils.isFKViolation(throwable)) {
future.completeExceptionally(new BadRequestException(HAS_ASSIGNED_RECORDS_MESSAGE));
} else {
future.completeExceptionally(cause);
}
}
return aVoid;
});
}
handle
方法仅在目标handle
实例完成后才调用其给定的BiFunction