I'm looking for some direction on how to log graphql related errors while also adding relevant information from the req object. I'm able to log the error object using the serverOptions.formatError function but unable to access the req object from here.
serverOptions: {
formatError(err) {
logger.error({ err }); // looking to add userID here which is available from jwt token in request object
return err;
},
},
I don't believe the following snippet from service.js ever actually triggers the this.sendError function:
try {
await this.prepareGraphQLSchema();
return this.graphqlHandler(req, res);
} catch (err) {
this.sendError(req, res, err);
}
...because moleculerApollo.js swallows the error by returning undefined in the catch handler:
try {
const { graphqlResponse, responseInit } = await runHttpQuery([req, res], {
method: req.method,
options,
query,
request: convertNodeHttpToRequest(req),
});
setHeaders(res, responseInit.headers);
return graphqlResponse;
} catch (error) {
if ("HttpQueryError" === error.name && error.headers) {
setHeaders(res, error.headers);
}
if (!error.statusCode) {
error.statusCode = 500;
}
res.statusCode = error.statusCode || error.code || 500;
res.end(error.message);
return undefined;
}
I'm looking for some direction on how to log graphql related errors while also adding relevant information from the req object. I'm able to log the error object using the serverOptions.formatError function but unable to access the req object from here.
I don't believe the following snippet from service.js ever actually triggers the
this.sendErrorfunction:...because moleculerApollo.js swallows the error by returning
undefinedin the catch handler: