// Formats an error using the default GraphQL `formatError` function, and // custom formatting using some other options. const formatError = (error: GraphQLError) => { // Get the appropriate formatted error object, including any extended error // fields if the user wants them. const formattedError = extendedErrors && extendedErrors.length ? extendedFormatError(error, extendedErrors) : defaultFormatError(error); // If the user wants to see the error’s stack, let’s add it to the // formatted error. if (showErrorStack) (formattedError as Record<string, any>)['stack'] = error.stack != null && showErrorStack === 'json' ? error.stack.split('\n') : error.stack; return formattedError; }
throw new Error('Received null or undefined error.'); const originalError = error.originalError as GraphQLErrorExtended; const exceptionDetails = originalError && fields ? pickPgError(originalError, fields) : undefined; return { message: error.message, locations: error.locations, path: error.path, };
if (validationErrors.length) { const error = new Error( 'Query validation failed: \n' + validationErrors.map(e => e.message).join('\n'), ); error['errors'] = validationErrors;
customFormatErrorFn(error) { if (!error.originalError) return error; const data = error.originalError.data; const message = error.message || "an error"; const code = error.originalError.code || 500; return { message, status: code, data }; }
graphiql: process.env.NODE_ENV === "development", customFormatErrorFn: error => { let original = error.originalError || {}; if (!original.details && original.errors) { original.details = error.originalError.stack.split("\n"); let message = original.message || error.message || "An error occurred"; let code = original.code || error.code; let details = original.details || error.details; let locations = error.locations; let path = error.path; let extensions = error.extensions;
formatError: error => { const message = error.message .replace("SequelizeValidationError: ", "") .replace("Validation error: ", "");
}), formatError: (error) => ({ code: error.extensions.code, message: error.message }) });