Example #1
0
 return errors.map(error => {
   if (formatter !== undefined) {
     try {
       return formatter(error);
     } catch (err) {
       console.error('Error in formatError function:', err);
       const newError = new Error('Internal server error');
       return formatError(newError);
     }
   } else {
     return formatError(error);
   }
 }) as Array<Error>;
Example #2
0
 return errors.map((error) => {
   if (options.formatError) {
     try {
       return options.formatError(error);
     } catch (err) {
       console.error('Error in formatError function:', err);
       const newError = new Error('Internal server error');
       return formatError(newError);
     }
   } else {
     return formatError(error);
   }
 }) as Array<Error>;
  const formatError = (error: GraphQLError) => {
    // Get the appropriate formatted error object, including any extended error
    // fields if the user wants them.
    const formattedError =
      options.extendedErrors && options.extendedErrors.length
        ? extendedFormatError(error, options.extendedErrors)
        : defaultFormatError(error);

    // If the user wants to see the error’s stack, let’s add it to the
    // formatted error.
    if (options.showErrorStack)
      (formattedError as object)['stack'] =
        error.stack != null && options.showErrorStack === 'json'
          ? error.stack.split('\n')
          : error.stack;

    return formattedError;
  };
export function defaultErrorFormatter(
  error,
): GraphQLFormattedError & PrismaErrorProps {
  const data: GraphQLFormattedError & PrismaErrorProps = formatError(error)

  if (
    error.originalError &&
    error.originalError.result &&
    error.originalError.result.errors &&
    error.originalError.result.errors.length === 1
  ) {
    const originalError = error.originalError.result.errors[0]
    if (originalError.message === error.message) {
      if (originalError.code) {
        data.code = originalError.code
      }
      if (originalError.requestId) {
        data.requestId = originalError.requestId
      }
    }
  }

  return data
}