织梦CMS - 轻松建站从此开始!

欧博ABG官网-欧博官方网址-会员登入

欧博allbetonErrorResume not working as expected

时间:2025-08-07 06:09来源: 作者:admin 点击: 0 次
I'm trying to use WebFlux and I'm seeing a behavior I don't quite understand, I suspect this is a bug in WebFlux or possibly Reactor, but I need confi

I'm trying to use WebFlux and I'm seeing a behavior I don't quite understand, I suspect this is a bug in WebFlux or possibly Reactor, but I need confirmation.

I've attempted to create a minimally reproducible case that consist of a very simple HandlerFunction that attempts to return an 200 response, but throws an exception during body creation and then attempts to use onErrorResume to instead return a 404 response.

The handler looks like so:

public Mono<ServerResponse> reproduce(ServerRequest request){ return ServerResponse.ok() .contentType(APPLICATION_JSON) .body(Mono.fromCallable(this::trigger),String.class) .onErrorResume(MinimalExampleException.class,e->ServerResponse.notFound().build()); }

I would expect when calling the associated endpoint that I would get a 404 response. Instead what I'm seeing is a 500 response with log messages indicating Spring believes there was an unhandled exception during request processing.

When I breakpoint inside of onErrorResume I see two handlers being registered, the one I register in the method above, as well as one that's being registered by Spring (inside of RouterFunctions.toHttpHandler) for instances of ResponseStatusException. Then during processing of the request I see only the second handler (the one registered by Spring) being called, not matching on the exception being thrown and then falling through to the root level handler.

Near as I can tell, Spring is overwriting onErrorResume at the router level preventing the one I registered in the Handler from being called. Is this the expected behavior? Is there a better way to accomplish what I'm attempting?

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-08-08 03:08 最后登录:2025-08-08 03:08
栏目列表
推荐内容