Dmitry Dyachkov
Dmitry Dyachkov

Reputation: 1785

NancyFx errors from async methods are not handled in OnError pipelines

I have NancyFX module with async POST method.

According to docs, all errors are handled like in here:

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

And errors are indeed handled if I code not async methods.

But I never get in callback when an exception is occurred within async methods.

Upvotes: 0

Views: 462

Answers (1)

Dmitry Dyachkov
Dmitry Dyachkov

Reputation: 1785

The issue has been in the incorrect POST method signature which I declared as async method, but forgot to make it async. And NancyFx engine didn't notice it.

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

After I has corrected it to

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

I started handling errors within

pipelines.OnError.AddItemToEndOfPipeline((ctx, exception) => {}

in Bootstrapper

Upvotes: 1

Related Questions