来自异步方法的 NancyFx 错误未在 OnError 管道中处理

NancyFx errors from async methods are not handled in OnError pipelines

我有带异步 POST 方法的 NancyFX 模块。

根据文档,所有错误的处理方式如下:

https://github.com/NancyFx/Nancy/wiki/The-Application-Before%2C-After-and-OnError-pipelines

如果我编写的不是异步方法,错误确实会得到处理。

但是当异步方法中发生异常时,我从来没有进入回调。

问题出在不正确的 POST 方法签名中,我将其声明为异步方法,但忘记将其设为异步。 而 NancyFx 引擎没有注意到它。

Post["/order/validation", true] = (parameters, token) => Task.FromResult...

我更正后

Post["/order/validation", true] = async (parameters, token) => await ...

我开始处理

内的错误
pipelines.OnError.AddItemToEndOfPipeline((ctx, exception) => {}

在引导程序中