Skip to content
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

Improve errors when subgraph service returns a non-2xx status code #2117

Closed
col opened this issue Nov 16, 2022 · 2 comments · Fixed by #2118
Closed

Improve errors when subgraph service returns a non-2xx status code #2117

col opened this issue Nov 16, 2022 · 2 comments · Fixed by #2118
Assignees

Comments

@col
Copy link
Contributor

col commented Nov 16, 2022

The Apollo Router handles non-2xx status codes from a subgraph service differently from the original Apollo Gateway. I would prefer this behaviour to remain consistent. I also think the current Router behaviour is insufficient as it currently ignores the status code completely and only returns an errors based on the content-type not being application/json.

As an example, if a subgraph service returns 401 Unauthorized (content-type: text/html), the Gateway would respond with something like this:

{
  "errors": [
    {
      "message": "401: Unauthorized",
      "extensions": {
        "code": "UNAUTHENTICATED",
        "response": {
          "url": "http://my-service/graphql",
          "status": 401,
          "statusText": "Unauthorized",
          "body": ""
        }
      }
    }
  ],
  "data": {
    "someField": null
  }
}

This is useful as it provide relevant info in the error response.

However the router will currently respond with:

{
  "data": null,
  "errors": [
    {
      "message": "HTTP fetch failed from 'my-service': subgraph didn't return JSON (expected content-type: application/json or content-type: application/graphql+json; found content-type: \"text/html\")",
      "path": [],
      "extensions": {
        "type": "SubrequestHttpError",
        "service": "my-service",
        "reason": "HTTP fetch failed from 'my-service': subgraph didn't return JSON (expected content-type: application/json or content-type: application/graphql+json; found content-type: \"text/html\")"
      }
    }
  ]
}

This is far less useful. I think the content-type is secondary issue to the fact that the status code was not 2xx but there is no mention of that in this error.

I understand that IF a subgraph chooses to return a non-2xx status code with a content-type of application/json then the response body, which probably contains a custom error, should still be parsed normally.

@o0Ignition0o
Copy link
Contributor

Hey, thanks for opening this issue!

I like the idea of adding more information on non 2XX errors if and only if the content-type is invalid.

bnjjj pushed a commit that referenced this issue Nov 21, 2022
…2118)

This PR tries to address Issue #2117

Here's an example of how the Router would now respond when a subgraph
service returns a non-2xx status code and content-type not set to
`application/json`.
```
{
  "data": null,
  "errors": [
    {
      "message": "HTTP fetch failed from 'my-service': 401 Unauthorized",
      "path": [],
      "extensions": {
        "type": "SubrequestHttpError",
        "service": "my-service",
        "reason": "HTTP fetch failed from 'my-service': 401 Unauthorized"
      }
    }
  ]
}
```
@abernix
Copy link
Member

abernix commented Nov 23, 2022

I think #2118 was meant to close this, but happy to re-open if that isn't the case! Thanks for the issue, and the PR!

@abernix abernix closed this as completed Nov 23, 2022
@abernix abernix removed the triage label Nov 23, 2022
goto-bus-stop pushed a commit that referenced this issue Nov 29, 2022
…2118)

This PR tries to address Issue #2117

Here's an example of how the Router would now respond when a subgraph
service returns a non-2xx status code and content-type not set to
`application/json`.
```
{
  "data": null,
  "errors": [
    {
      "message": "HTTP fetch failed from 'my-service': 401 Unauthorized",
      "path": [],
      "extensions": {
        "type": "SubrequestHttpError",
        "service": "my-service",
        "reason": "HTTP fetch failed from 'my-service': 401 Unauthorized"
      }
    }
  ]
}
```
garypen pushed a commit that referenced this issue Nov 30, 2022
…2118)

This PR tries to address Issue #2117

Here's an example of how the Router would now respond when a subgraph
service returns a non-2xx status code and content-type not set to
`application/json`.
```
{
  "data": null,
  "errors": [
    {
      "message": "HTTP fetch failed from 'my-service': 401 Unauthorized",
      "path": [],
      "extensions": {
        "type": "SubrequestHttpError",
        "service": "my-service",
        "reason": "HTTP fetch failed from 'my-service': 401 Unauthorized"
      }
    }
  ]
}
```
@BrynCooke BrynCooke modified the milestones: v1-NEXT, v1.5.0 Dec 2, 2022
@garypen garypen added this to the v1.5.0 milestone Dec 5, 2022
@BrynCooke BrynCooke modified the milestone: v1.5.0 Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants