UNPKG

graphql-yoga

Version:

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

44 lines (43 loc) 1.44 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; } // Original error should be removed const extensions = { ...error.extensions, unexpected: true, }; if (isDev) { extensions.originalError = { message: error.originalError.message, stack: error.originalError.stack, }; } return createGraphQLError(message, { nodes: error.nodes, source: error.source, positions: error.positions, path: error.path, extensions, }); } return error; } return createGraphQLError(message, { extensions: { unexpected: true, originalError: isDev ? error instanceof Error ? { message: error.message, stack: error.stack, } : error : undefined, }, }); };