Skip to content

Improve GraphQL error handling by mapping all DataApiBuilderException types to appropriate HTTP status codes #2692

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented May 19, 2025

What's changed

This PR enhances the DabGraphQLResultSerializer class to properly map all types of DataApiBuilderException.SubStatusCodes to their appropriate HTTP status codes in GraphQL responses.

Previously, the serializer only handled one specific error type (DatabaseInputError) and would return BadRequest (400) status code for it, while defaulting to server error (500) for all other exceptions.

Now, the serializer has been updated to:

  1. Map authentication errors to 401 Unauthorized
  2. Map authorization errors to 403 Forbidden
  3. Map entity/item not found errors to 404 NotFound
  4. Map input validation errors to 400 BadRequest
  5. Map unsupported features to 501 NotImplemented
  6. Map conflict errors to 409 Conflict
  7. Map server-side errors to 500 InternalServerError

This implementation ensures that GraphQL responses have the appropriate HTTP status codes that match the nature of the error, which improves API consistency and allows clients to better handle different error types.

The class documentation has also been updated to clearly explain the purpose and behavior of the serializer.

Fixes #2691.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.fwupd.org
  • crl3.digicert.com
    • Triggering command: dotnet build src/Azure.DataApiBuilder.sln (dns block)
  • crl4.digicert.com
    • Triggering command: dotnet build src/Azure.DataApiBuilder.sln (dns block)
  • dc.services.visualstudio.com
  • ocsp.digicert.com
    • Triggering command: dotnet build src/Azure.DataApiBuilder.sln (dns block)
  • s.symcb.com
    • Triggering command: dotnet build src/Azure.DataApiBuilder.sln (dns block)
  • s.symcd.com
    • Triggering command: dotnet build src/Azure.DataApiBuilder.sln (dns block)
  • test
  • ts-crl.ws.symantec.com
    • Triggering command: dotnet build src/Azure.DataApiBuilder.sln (dns block)
  • ts-ocsp.ws.symantec.com
    • Triggering command: dotnet build src/Azure.DataApiBuilder.sln (dns block)
  • www.microsoft.com
    • Triggering command: dotnet build src/Azure.DataApiBuilder.sln (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…LResultSerializer

Co-authored-by: Aniruddh25 <3513779+Aniruddh25@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Inspect all DataApiBuilderExceptions to determine the correct status code of HotChocolate responses Improve GraphQL error handling by mapping all DataApiBuilderException types to appropriate HTTP status codes May 19, 2025
@Copilot Copilot AI requested a review from Aniruddh25 May 19, 2025 20:06
Copilot finished work on behalf of Aniruddh25 May 19, 2025 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inspect all DataApiBuilderExceptions to determine the correct status code of HotChocolate responses
2 participants