Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const createGraphQLErrorFormatter = (req?: express$Request) => (
error: GraphQLError
) => {
console.log('error', error);
const isUserError = error.originalError
? error.originalError[IsUserError]
: false;
let sentryId = 'ID only generated in production';
if (!isUserError) {
if (process.env.NODE_ENV === 'production') {
sentryId = Raven.captureException(
error,
req && Raven.parsers.parseRequest(req)
);
}
}
return {
message: isUserError ? error.message : `Internal server error: ${sentryId}`,
// Hide the stack trace in production mode
stack:
!process.env.NODE_ENV === 'production' ? error.stack.split('\n') : null,
};
};
const createGraphQLErrorFormatter = (req?: express$Request) => (
error: GraphQLError
) => {
const isUserError = error.originalError
? error.originalError[IsUserError]
: false;
let sentryId = 'ID only generated in production';
if (!isUserError) {
if (process.env.NODE_ENV === 'production') {
sentryId = Raven.captureException(
error,
req && Raven.parsers.parseRequest(req)
);
}
}
return {
message: isUserError ? error.message : `Internal server error: ${sentryId}`,
// Hide the stack trace in production mode
stack:
!process.env.NODE_ENV === 'production' ? error.stack.split('\n') : null,
};
};
const baseURL = req.baseUrl
// TODO: change the href to not include variables when `variables` is null or undefined.
const encodedVars = encodeURIComponent(JSON.stringify(variables))
const encodedQuery = encodeURIComponent(query)
const href = `${baseURL}/graphiql?variables=${encodedVars}&query=${encodedQuery}`
raven.captureException(error.originalError || error, {
tags: { graphql: "exec_error" },
extra: {
source: (error.source && error.source.body) || query,
positions: error.positions,
path: error.path,
variables,
href,
},
...raven.parsers.parseRequest(req),
})
}
autoBreadcrumbs: true,
captureUnhandledRejections: true,
environment: keys.EXECUTION_ENV,
}).install();
}
exports.log = (msg, meta) => {
if (sentryEnabled) {
if (meta.level === 'error' || meta.level === 'fatal') {
Raven.captureException(msg, meta);
}
Raven.captureMessage(msg, meta);
}
};
exports.parseRequest = Raven.parsers.parseRequest;
return (error) => {
if (enableSentry) {
if (shouldLogError(error.originalError)) {
raven.captureException(
error,
assign(
{},
{
tags: { graphql: "exec_error" },
extra: {
source: error.source && error.source.body,
positions: error.positions,
path: error.path,
},
},
raven.parsers.parseRequest(req),
),
)
}
}
return {
message: error.message,
locations: error.locations,
stack: isProduction ? null : error.stack,
}
}
}