Skip to content

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

Merged
bnjjj merged 8 commits intoapollographql:devfrom
col:unauthorized-status-code-from-subgraph
Nov 21, 2022
Merged

Improve errors when subgraph service returns a non-2xx status code#2118
bnjjj merged 8 commits intoapollographql:devfrom
col:unauthorized-status-code-from-subgraph

Conversation

@col
Copy link
Contributor

@col col commented Nov 16, 2022

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"
      }
    }
  ]
}

Closes #2117

Copy link
Contributor

@o0Ignition0o o0Ignition0o left a comment

Choose a reason for hiding this comment

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

This looks really great! 🎉


By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/2096

### Improve errors when subgraph returns non-2xx status code ([Issue #2117](https://github.com/apollographql/router/issues/2117))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we convey this will only happen with non graphql subgraph responses ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure 👍


let make_svc = make_service_fn(|_conn| async { Ok::<_, Infallible>(service_fn(handle)) });
let server = Server::bind(&socket_addr).serve(make_svc);
if let Err(e) = server.await {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we panic instead ? If it's for a test it's better to directly panic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just copied the precedence set in the other emulate_* functions.
This is my first time writing any Rust code so I'll leave this judgement call up to you.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I know it's our mistake, we should change the other ones. We will... one day :)

Comment on lines 407 to 409
if let Err(e) = server.await {
eprintln!("server error: {}", e);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if let Err(e) = server.await {
eprintln!("server error: {}", e);
}
server.await.unwrap()

cc @col

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Job done.

@bnjjj bnjjj merged commit 9493735 into apollographql:dev Nov 21, 2022
@col col deleted the unauthorized-status-code-from-subgraph branch November 23, 2022 08:06
garypen pushed a commit that referenced this pull request 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 added this to the v1.5.0 milestone Dec 3, 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
@BrynCooke BrynCooke mentioned this pull request Dec 5, 2022
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.

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

5 participants