英文:
retrieving chain data in Mono/Flux error handlers
问题
I would like to be able to use chain data in an error handler. Condensed my issue looks like this:
request.bodyToMono(MyRequest.class)
.map(dosomestuff)
.onErrorResume(dosomeerrorhandling)
request is a ServerRequest. In the request message is a requestId field. I don't know the requestId until the message has been extracted. The message is then processed (dosomestuff) during which an exception may occur. That will be "caught" by onErrorResume and at that point I'd like to know the requestId.
I don't think I can put the requestId into the Mono context as it's not available until after the Mono has started. I could write a custom exception and place the requestId in that, but I'm concerned the extra exception handling will get messy.
Any other suggestions appreciated. Perhaps I'm just not thinking about the problem in the right way? - it's been a long day.
英文:
I would like to be able to use chain data in an error handler. Condensed my issue looks like this:
request.bodyToMono(MyRequest.class)
.map(dosomestuff)
.onErrorResume(dosomeerrorhandling)
request is a ServerRequest. In the request message is a requestId field. I don't know the requestId until the message has been extracted. The message is then processed (dosomestuff) during which an exception may occur. That will be "caught" by onErrorResume and at that point I'd like to know the requestId.
I don't think I can put the requestId into the Mono context as it's not available until after the Mono has started. I could write a custom exception and place the requestId and that, but I'm concerned the extra exception handling will get messy.
Any other suggestions appreciated. Perhaps I'm just not thinking about the problem in the right way? - it's been a long day.
答案1
得分: 1
A possible approach:
request.bodyToMono(MyRequest.class).flatMap(request -> Mono.just(request)
.map()
// whatever
.onErrorResume(/* any lambda, the request is available there */)
);
英文:
A possible approach:
request.bodyToMono(MyRequest.class).flatMap(request -> Mono.just(request)
.map()
// whatever
.onErrorResume(/* any lambda, the request is available there */)
);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论