UNPKG

graphql-yoga

Version:

<div align="center"><img src="./website/public/cover.png" width="720" /></div>

46 lines (45 loc) 1.58 kB
import { createGraphQLError } from '@graphql-tools/utils'; import { isGraphQLError } from '../error.js'; export const maskError = (error, message, isDev = globalThis.process?.env?.['NODE_ENV'] === 'development') => { if (isGraphQLError(error)) { if (error.originalError) { if (error.originalError.name === 'GraphQLError') { return error; } return createGraphQLError(message, { nodes: error.nodes, source: error.source, positions: error.positions, path: error.path, extensions: { code: 'INTERNAL_SERVER_ERROR', ...error.extensions, unexpected: true, ...(isDev ? { originalError: { message: error.originalError.message, stack: error.originalError.stack, }, } : {}), }, }); } return error; } return createGraphQLError(message, { extensions: { code: 'INTERNAL_SERVER_ERROR', unexpected: true, originalError: isDev ? error instanceof Error ? { message: error.message, stack: error.stack, } : error : undefined, }, }); };