OData / OData/AspNetCoreOData

Error returned is 500 when 400 is expected

Open
#733 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Assemblies affected
ASP.NET Core OData 8.x

Describe the bug
When calling a OData endpoint, I get a 500 error instead of a 400. This occurs when adding an invalid key in the URL. Example odata/books/1' or odata/books/aaaaaaaa .

Reproduce steps
Using my example here https://github.com/berubejp/webapiodata500 which is a basic web api with EF Core in memory and OData.

When calling odata/books/aaaaaaaa, I get a 500 response.
When calling odata/books/1', I get a 500 response. Notice the single quote at the end or the URL.

The error is ODataException: The key value (xxx) from request is not valid.

Expected behavior
This should be a 400 error since this is a client error.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction project and the ASP.NET Core OData request path for an invalid key such as odata/books/aaaaaaaa or odata/books/1'. Trace how the reported ODataException becomes the HTTP response, then verify that these malformed-key requests return 400 rather than 500.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.