Skip to content

Commit

Permalink
fix: catch fetch errors (#11)
Browse files Browse the repository at this point in the history
If the fetch fails (e.g. due to hostname resolution failure), the promise is not rejected until the 30 second timeout.

Wrapping this in a try/catch allows the promise to be rejected instantly.
  • Loading branch information
kane-c authored and nodkz committed Nov 15, 2018
1 parent 58887e1 commit 0c11165
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ export default class RelayServerSSR {
}, 30000);

let payload = null;
if (hasSchema) {
payload = await graphql({
...graphqlArgs,
source: req.getQueryString(),
variableValues: req.getVariables(),
});
} else {
payload = await next(r);
try {
if (hasSchema) {
payload = await graphql({
...graphqlArgs,
source: req.getQueryString(),
variableValues: req.getVariables(),
});
} else {
payload = await next(r);
}
resolve(payload);
} catch (e) {
reject(e);
}
resolve(payload);
});
this.cache.set(cacheKey, gqlResponse);

Expand Down

0 comments on commit 0c11165

Please sign in to comment.