-
Notifications
You must be signed in to change notification settings - Fork 154
Open
Labels
internally-reviewedInternally reviewedInternally reviewed
Description
At the moment, when using integrated timeouts for each subgraph, we can get a vague answer "Failed to fetch from Subgraph X". However, I would like to receive a clear answer that a timeout has occurred.
I suggest integrating a similar implementation in v2/loader.go.:
func (l *Loader) renderErrorsFailedToFetch(fetchItem *FetchItem, res *result, reason string) error {
l.ctx.appendSubgraphErrors(res.err, NewSubgraphError(res.ds, fetchItem.ResponsePath, reason, res.statusCode))
errorObject, err := astjson.ParseWithoutCache(l.renderSubgraphBaseError(res.ds, fetchItem.ResponsePath, reason))
var errorObject *astjson.Value
var err error
if res.statusCode == 0 && reason == "" {
errorObject, err = astjson.ParseWithoutCache(l.renderTimeoutFetchError(fetchItem, res))
} else {
errorObject, err = astjson.ParseWithoutCache(l.renderSubgraphBaseError(res.ds, fetchItem.ResponsePath, reason))
}
if err != nil {
return err
}
l.setSubgraphStatusCode([]*astjson.Value{errorObject}, res.statusCode)
astjson.AppendToArray(l.resolvable.errors, errorObject)
return nil
}
func (l *Loader) renderTimeoutFetchError(fetchItem *FetchItem, res *result) string {
path := ""
switch f := fetchItem.Fetch.(type) {
case *SingleFetch:
path = getJsonReadyPath(f.Info.RootFields)
case *EntityFetch:
path = getJsonReadyPath(f.Info.RootFields)
default:
path = ""
}
return fmt.Sprintf(
`{"path":[%s],
"extensions":{"code":"GlobalTimeoutError", "type":"GlobalTimeoutError", "classification":"GlobalTimeoutError"},
"locations": [],
"message":"GlobalTimeoutError"}`,
path,
)
}
Or go to another level to allow developers to customize errors without changing the library code.
Metadata
Metadata
Assignees
Labels
internally-reviewedInternally reviewedInternally reviewed