Skip to content

Return 400 for invalid If-Match values#3415

Open
aaronburtle wants to merge 6 commits intomainfrom
dev/aaronburtle/fix-if-match-500-response
Open

Return 400 for invalid If-Match values#3415
aaronburtle wants to merge 6 commits intomainfrom
dev/aaronburtle/fix-if-match-500-response

Conversation

@aaronburtle
Copy link
Copy Markdown
Contributor

Why make this change?

Closes #3397

What is this change?

When DeterminePatchPutSemantics threw a DataApiBuilderException for an invalid If-Match value, the exception was thrown before entering HandleOperation and the try-catch block within. This is where we convert DataApiBuilderException into structured JSON error response. We therefore move the DeterminePatchPutSemantics call inside of the try-catch block within HandleOperation, gating the function behind a check of the operation type so that it only applies to Upsert and UpsertIncremental operations.

How was this tested?

Added a test for Put and a test for Patch to validate the new behavior.

Sample Request(s)

Any valid Put or Patch with headers using If-Match with a value other than *

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes REST PUT/PATCH behavior so invalid If-Match header values correctly return a structured 400 Bad Request JSON error (instead of bubbling out and producing a 500/empty response), aligning REST error handling with DAB’s DataApiBuilderException conversion path.

Changes:

  • Move DeterminePatchPutSemantics evaluation into HandleOperation’s try/catch so invalid If-Match values are translated into a 400 JSON error response.
  • Gate DeterminePatchPutSemantics so it only applies to Upsert / UpsertIncremental.
  • Add PUT and PATCH integration tests asserting 400 + expected error message for invalid If-Match values.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Service/Controllers/RestController.cs Moves If-Match validation into the controller’s exception-handling path to return 400 JSON errors.
src/Service.Tests/SqlTests/RestApiTests/Put/PutApiTestBase.cs Adds PUT test verifying invalid If-Match returns 400 with expected message.
src/Service.Tests/SqlTests/RestApiTests/Patch/PatchApiTestBase.cs Adds PATCH test verifying invalid If-Match returns 400 with expected message.

aaronburtle and others added 4 commits April 6, 2026 11:18
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@aaronburtle aaronburtle added the 2.0 label Apr 7, 2026
@aaronburtle aaronburtle added this to the April 2026 milestone Apr 7, 2026
@aaronburtle aaronburtle moved this from Todo to Review In Progress in Data API builder Apr 7, 2026
@Aniruddh25 Aniruddh25 enabled auto-merge (squash) April 11, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

[Bug]: Invalid If-Match value returns 500 instead of 400

5 participants