gpt4 book ai didi

java - io.reactivex.exceptions.UndeliverableException 异常无法传递给消费者,因为它已经取消/处置

转载 作者:行者123 更新时间:2023-12-04 15:03:18 26 4
gpt4 key购买 nike

使用 completable 时出现 UndeliverableException

public Completable createBucketWithStorageClassAndLocation() {
return Completable.complete()
.doFinally(() -> {
Bucket bucket =
storage.create(
BucketInfo.newBuilder(googleUploadObjectConfiguration.bucketName())
.setStorageClass(storageClass)
.setLocation(googleUploadObjectConfiguration.locationName())
.build());
}).doOnError(error -> LOG.error(error.getMessage()));
}
异常是从 Google 存储中抛出的,这是正确的,但试图处理 doOnError方法
Caused by: com.google.cloud.storage.StorageException: You already own this bucket. Please select another name.
RXJava 异常
io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | com.google.cloud.storage.StorageException: You already own this bucket. Please select another name.
at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367)
at io.reactivex.internal.operators.completable.CompletableDoFinally$DoFinallyObserver.runFinally(CompletableDoFinally.java:99)
at io.reactivex.internal.operators.completable.CompletableDoFinally$DoFinallyObserver.onComplete(CompletableDoFinally.java:79)
at io.micronaut.reactive.rxjava2.RxInstrumentedCompletableObserver.onComplete(RxInstrumentedCompletableObserver.java:64)
at io.reactivex.internal.disposables.EmptyDisposable.complete(EmptyDisposable.java:68)
at io.reactivex.internal.operators.completable.CompletableEmpty.subscribeActual(CompletableEmpty.java:27)
at io.reactivex.Completable.subscribe(Completable.java:2309)
at io.micronaut.reactive.rxjava2.RxInstrumentedCompletable.subscribeActual(RxInstrumentedCompletable.java:51)
at io.reactivex.Completable.subscribe(Completable.java:2309)
at io.reactivex.internal.operators.completable.CompletableDoFinally.subscribeActual(CompletableDoFinally.java:43)
at io.reactivex.Completable.subscribe(Completable.java:2309)
at io.micronaut.reactive.rxjava2.RxInstrumentedCompletable.subscribeActual(RxInstrumentedCompletable.java:51)
at io.reactivex.Completable.subscribe(Completable.java:2309)
at io.reactivex.internal.operators.completable.CompletablePeek.subscribeActual(CompletablePeek.java:51)
at io.reactivex.Completable.subscribe(Completable.java:2309)
at io.micronaut.reactive.rxjava2.RxInstrumentedCompletable.subscribeActual(RxInstrumentedCompletable.java:51)
at io.reactivex.Completable.subscribe(Completable.java:2309)
at io.reactivex.Completable.subscribe(Completable.java:2410)
at fete.bird.StartUp.onApplicationEvent(StartUp.java:24)
at fete.bird.StartUp.onApplicationEvent(StartUp.java:12)
at io.micronaut.context.DefaultBeanContext.notifyEventListeners(DefaultBeanContext.java:1323)
at io.micronaut.context.DefaultBeanContext.publishEvent(DefaultBeanContext.java:1308)
at io.micronaut.http.server.netty.NettyHttpServer.fireStartupEvents(NettyHttpServer.java:507)
at io.micronaut.http.server.netty.NettyHttpServer.start(NettyHttpServer.java:350)
at io.micronaut.http.server.netty.NettyHttpServer.start(NettyHttpServer.java:113)
at io.micronaut.runtime.Micronaut.lambda$start$2(Micronaut.java:77)
at java.base/java.util.Optional.ifPresent(Optional.java:176)
at io.micronaut.runtime.Micronaut.start(Micronaut.java:75)
at io.micronaut.runtime.Micronaut.run(Micronaut.java:311)
at io.micronaut.runtime.Micronaut.run(Micronaut.java:297)
at fete.bird.FeteBirdServiceApplication.main(FeteBirdServiceApplication.java:16)
来自 rxjava 文档 https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling我需要处理应用程序中的错误。
我需要写下面的代码,
/ If Java 8 lambdas are supported
RxJavaPlugins.setErrorHandler(e -> { });
我的问题是我应该在哪里写这段代码。我有一个使用 java 的 Micronaut 应用程序,或者这是处理异常的唯一方法。

最佳答案

使用 Completable.fromAction也许 try catch 异常而不是 doFinally装置:

Completable.fromAction(() -> {
try {
Bucket bucket = storage.create(
BucketInfo.newBuilder(googleUploadObjectConfiguration.bucketName())
.setStorageClass(storageClass)
.setLocation(googleUploadObjectConfiguration.locationName())
.build());
} catch (Throwable error) {
LOG.error(error.getMessage());
}
})

关于java - io.reactivex.exceptions.UndeliverableException 异常无法传递给消费者,因为它已经取消/处置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66576755/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com