web-dev-qa-db-fra.com

io.reactivex.exception.undeliverAnceptibleException L'exception n'a pas pu être livrée au consommateur car elle a déjà annulé / disposé

Obtenir une exception non livrable lors de l'utilisation completable

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()));
    }

L'exception est lancée à partir du stockage Google qui est correct, mais essayant de gérer la méthode doOnError

Caused by: com.google.cloud.storage.StorageException: You already own this bucket. Please select another name.

Exception 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)

De la documentation Rxjava https://github.com/reactivex/rxjava/wiki/What's-Different-in-2.0#Error-handling Je dois gérer l'erreur dans l'application.

J'ai besoin d'écrire le code ci-dessous,

/ If Java 8 lambdas are supported
RxJavaPlugins.setErrorHandler(e -> { });

Ma question est où devrais-je écrire ce code. J'ai une application Micronaut en utilisant Java ou c'est le seul moyen de gérer l'exception.

3
San Jaisy

Utiliser Completable.fromAction Et peut-être essayer-attraper l'exception au lieu de ce doFinally Contraption:

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