Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global exceptions handling #123

Closed
oleneveu opened this issue Feb 14, 2024 · 2 comments · Fixed by #126
Closed

Global exceptions handling #123

oleneveu opened this issue Feb 14, 2024 · 2 comments · Fixed by #126
Labels
question Further information is requested

Comments

@oleneveu
Copy link

I would like to add a global exception handler for all commands.

The default behavior is that all exceptions are catched by the handler in HandleExceptionAndExitMiddleware.

I have tried to add another middleware to intercept the exception:

var builder = CoconaApp.CreateBuilder(args);
var app = builder.Build();
var commandDispatcher = app.Services.GetRequiredService<ICoconaCommandDispatcherPipelineBuilder>();
commandDispatcher.UseMiddleware<MyExceptionHandlerMiddleware>();

That does not work, and my understanding is that the HandleExceptionAndExitMiddleware is added later and takes precedence over my own middleware.

Is there any other way to intercept the exceptions ?

@mayuki mayuki added the question Further information is requested label Feb 15, 2024
@mayuki
Copy link
Owner

mayuki commented Feb 15, 2024

You can apply filters with app.UseFilter to handle exceptions in the same way as middleware.

@oleneveu
Copy link
Author

Thanks, that's what I was looking for.
Sorry for not having found that by myself...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants