-
-
Notifications
You must be signed in to change notification settings - Fork 158
Calling 'AddJsonApi' bypass all the exception handler middlewares #501
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
Comments
IMHO, the |
I think being able to define your own exception filter is the better option here, and i get your point, but it should also happen for the mixin controller, not the derived jsonapicontroller |
Providing my own exception filter sure is a powerful option. But I feel that calling var controllerActionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
if (controllerActionDescriptor == null)
{
return;
}
var mixinControllerType = typeof(JsonApiControllerMixin);
if (!mixinControllerType.IsAssignableFrom(controllerActionDescriptor.ControllerTypeInfo))
{
return; // Error is not from a JSONAPI controller. Don't intervene in the process.
} What do you think of the idea? In the mean time, I have no choice but to manually remove the JsonApiExceptionFilter from the list of filters added to MVC. |
Another option would be to just inspect the ContentType of the request and only handle failures for application/vnd.api+json |
For v4.0 I think we could implement the proposal of either @mabead or @jaredcnance. I'm not sure which one is better |
I disagree with @mabead that jsonapi should not change existing code base, as the errors should be Json:api spec. But you should be allowed to turn them off, or atleast alter the conditions under which they are run. |
As a part of fixing failing tests for #504 , I'm currently looking into this now. The official docs have the following to say about the usage of exception filters.
So this suggests it would be a good practice to implement something like @mabead proposes, because with this it targets only the JsonApiDotNetCore actions. On top of that, to allow for extensibility, we could stuff this functionality in a service that we inject in the exception filter, allowing users to customize how the filter behaves without having to mess with removing and readding filters. |
Custom exception handling is now supported, see #586 |
Description
Before using JsonApiDotNetCore, I had an ASP.NET Core middleware that had the responsibility to reformat all exceptions that occured in my controllers. This middleware was almost identical to this one.
As soon as I started to use JsonApiDotNetCore by calling
AddJsonApi
, my middleware stopped working. This is because AddJsonApi registers an exception filter:JsonApiDotNetCore/src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs
Line 82 in 8570b21
This exception filter handles all exceptions. My middleware is therefore unable to detect the exception.
Is there a way to disable this exception filter or to limit this exception filter to the routes that to use JSONAPI? My routes that don't use JSONAPI should still use my exception middleware.
Environment
The text was updated successfully, but these errors were encountered: