You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The AutoQueryableFilter in ASPNETCORE.Filter throws a null reference exception if the action throws an exception. Filter should check context.Exception and context.ExceptionHandled before invoking filter behaviour?
The text was updated successfully, but these errors were encountered:
Encountered this issue as well and it's bad.
We use exceptions and filters to easily return some specific errors to front-end.
For example, we might have this controller:
[HttpGet,AutoQueryable]publicIQueryable<object>Api(boolisError){if(isError)thrownewBusinessException("Is error is true!");returnnew[]{new{}}.AsQueryable();}
We have a global filter that turns BusinessException into a 406 response with the error message in body, which is then handled by the front-end and displayed as a specific error.
The problem here is that throwing any exception is caught by AutoQueryable filter, which then throws NullReferenceException.
A better behavior, as suggested by @springyboy, would be to do nothing (passthrough) when context.Exception is set.
Another minor problem is when the controller returns null. The filter throws a very generic Exception with message "Unable to retrieve value of IQueryable from context result".
You can say that the contract for AutoQueryable is a non-null value, but it might be more useful to consider null as empty and automatically return an empty array (or wrapper with count: 0).
Alternatively you could let null passthrough as well (which by default turns into a 204 No content response).
The AutoQueryableFilter in ASPNETCORE.Filter throws a null reference exception if the action throws an exception. Filter should check context.Exception and context.ExceptionHandled before invoking filter behaviour?
The text was updated successfully, but these errors were encountered: