-
Notifications
You must be signed in to change notification settings - Fork 160
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
OData 9.0 Returning 200 with Broken JSON #1345
Comments
This happens when an error is found during serialization I think. Can you try just manually materializing your query upfront in the controller to see what the underlying exception is? You should be able to inject |
Also seems similar to this: |
I created a custom attribute that inherits from EnableQueryAttribute and overrides the ValidateQuery method to manage OData errors using our standard error model. The issue arises with certain OData queries that are valid according to OData, pass ValidateQuery, and get translated into LINQ. When EF Core processes these queries, OData starts to create a response with a 200 OK status, but an exception occurs inside EF Core during execution. As a result, the response returns a 200 OK with the embedded error, which makes it difficult for my exception-handling middleware to properly catch it. This is our CustomEnableQueryAttribute :
Here's an example of a query that triggers the issue:
The resulting error message is:
When I try to handle this error in middleware, I get an additional issue:
Here’s the LINQ query that EF Core tries to process:
To work around this, I tested removing [EnableQuery] and using .ToList() on the result. This returns a null response without any OData errors. It would be ideal if OData handled exceptions that occur specifically within EF Core execution. |
I've also ran into this behavior in the past several times and it is not great at all. Hopefully the team will be able to fix this and properly report the errors as expected. |
Hello everyone,
I'm currently working with .NET 8, OData 9, EF Core 8, and PostgreSQL. When I make requests using certain OData queries that are valid in OData but incompatible with EF Core, the response I receive is broken JSON with 200 status code
instead of a clear error message. Here are a couple of example queries that reproduce the issue:
?$expand=Orders($compute=Amount div 0 as test; $select = *;)
?$expand=AllMovies($filter=category/any(x: x eq null))
If anyone has suggestions or knows of a way to handle or catch these errors gracefully, I’d appreciate your input.
The text was updated successfully, but these errors were encountered: