Skip to content

Conversation

Copilot
Copy link
Contributor

@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.

@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
@souvikghosh04
Copy link
Contributor

/azp run

Copy link

Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

/// </summary>
public class DabGraphQLResultSerializer : DefaultHttpResultSerializer
{
public override HttpStatusCode GetStatusCode(IExecutionResult result)
{
if (result is IQueryResult queryResult && queryResult.Errors?.Count > 0)
{
if (queryResult.Errors.Any(error => error.Code == DataApiBuilderException.SubStatusCodes.DatabaseInputError.ToString()))
// Check if any of the errors are from DataApiBuilderException by looking at error.Code
foreach (var error in queryResult.Errors)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a really good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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
4 participants