Skip to content

Commit 4910316

Browse files
committed
woof.
1 parent 40c9a1c commit 4910316

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

docs/error_handling.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,28 @@ Failed stitching requests can be tricky to debug because it's not always obvious
44

55
### Supergraph errors
66

7-
When exceptions happen while executing requests within the stitching layer, they will be rescued by the stitching client and trigger an `on_error` hook. You should add your stack's error reporting here and return a formatted error message to appear in [GraphQL errors](https://spec.graphql.org/June2018/#sec-Errors) for the request.
7+
When exceptions happen while executing requests within the stitching layer, they will be rescued by the stitching client and trigger an `on_error` hook. You should add your stack's error reporting here:
88

99
```ruby
1010
client = GraphQL::Stitching::Client.new(locations: { ... })
1111
client.on_error do |request, err|
1212
# log the error
1313
Bugsnag.notify(err)
14+
end
15+
```
1416

15-
# return a formatted message for the public response
16-
"Whoops, please contact support abount request '#{request.context[:request_id]}'"
17+
To modify the format of returned error messages that appear in [GraphQL errors](https://spec.graphql.org/June2018/#sec-Errors), extend `Client` and define your own `build_graphql_error` method:
18+
19+
```ruby
20+
class MyClient < GraphQL::Stitching::Client
21+
def build_graphql_error(request, err)
22+
graphql_error = super(request, err)
23+
graphql_error["message"] << ". Contact support about Request ID #{request.context[:request_id]}"
24+
graphql_error
25+
end
1726
end
1827

19-
# Result:
20-
# { "errors" => [{ "message" => "Whoops, please contact support abount request '12345'" }] }
28+
client = MyClient.new(locations: { ... })
2129
```
2230

2331
### Subgraph errors

0 commit comments

Comments
 (0)