How to use the apollo-server-express.ApolloError function in apollo-server-express

To help you get started, we’ve selected a few apollo-server-express examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github juicycleff / ultimate-backend / apps / service-tenant / src / cqrs / query / handlers / tenant / get-tenants.handler.ts View on Github external
async execute(query: GetTenantsQuery): Promise {
    Logger.log(query, 'GetTenantsQuery'); // write here
    const { where, user } = query;

    if (!user) { throw Error('Missing get current user'); }

    try {
      return await this.tenantRepository.find({ conditions: {...where, ownerId: new ObjectId(user.id)} });
    } catch (e) {
      throw new ApolloError(e);
    }
  }
}
github goemonjs / goemon / src / routes / impl / gapi / member / resolvers / profile.ts View on Github external
async function getProfile(parent: any, args: any, context: { me: GUser }, info: any) {
  const condition = { email: context.me.email };
  let user: UserDocument | null = await Users.findOne(condition).exec();
  if (user == null) {
    throw new ApolloError('User does not exist.');
  }
  let profile: Profile = {
    email: user.email,
    displayName: user.displayName,
    isEmailVeried: user.isEmailVerified,
    image: user.profile.image,
    firstName: user.profile.firstName,
    middleName: user.profile.middleName,
    lastName: user.profile.lastName,
    birthDay: user.profile.birthDay && user.profile.birthDay.toISOString(),
    createdAt: user.createdAt && user.createdAt.toISOString(),
    updatedAt: user.updatedAt && user.updatedAt.toISOString()
  };
  return profile;
}
github origen-chat / api / projects / api / src / server / query / resolver.ts View on Github external
export const resolveUser: Resolver = async (
  root,
  args,
) => {
  const { uniqueUsername } = args;

  const user = await users.getUserByUniqueUsername(uniqueUsername);

  if (!user) {
    throw new ApolloError('user not found');
  }

  return user;
};
github connect-foundation / 2019-02 / server-api / src / apollo / resolvers / histories.js View on Github external
const getHistories = async (_, __, { user }) => {
  try {
    const histories = (await Histories.find({ userId: user.userId })) || [];
    const payloads = await Promise.all(histories.map((history) => history.toPayload()));

    return payloads;
  } catch (err) {
    throw new ApolloError(err.message);
  }
};
github gatsbyjs / api.gatsbyjs.org / src / lib / shopify.js View on Github external
userErrors {
              field
              message
            }
          }
        }
      `
    );

    if (response.userErrors.length > 0) {
      throw new Error(response.userErrors[0].message);
    }

    return response.customer.id;
  } catch (error) {
    throw new ApolloError(error.message);
  }
};
github aerogear-attic / data-sync-server / server / lib / util / internalServerError.js View on Github external
function newInternalServerError (context) {
  let errorId = (context && context.request) ? context.request.id : uuid.v4()
  const genericErrorMsg = `An internal server error occurred, please contact the server administrator and provide the following id: ${errorId}`
  return new ApolloError(genericErrorMsg, INTERNAL_SERVER_ERROR, { id: errorId })
}
github gatsbyjs / api.gatsbyjs.org / src / lib / shopify.js View on Github external
}
      }
    `
  );

  const errors = response.data.data.tagsAdd.userErrors;

  if (response.errors || errors.length > 0) {
    const allErrors = [].concat(
      response.errors.map(({ message }) => message),
      errors.map(({ message }) => message)
    );

    logger.error(allErrors);

    throw new ApolloError(allErrors[0]);
  }

  logger.verbose(`Added new tags: ${tags.join(', ')}`);
};
github juicycleff / ultimate-backend / apps / service-payment / src / cqrs / query / handlers / card / get-cards.handler.ts View on Github external
const cacheData = await this.cacheStore.get(cacheKey);
      if (cacheData !== undefined && typeof cacheData !== 'undefined') {
        return cacheData;
      }

      const cardObjs = await this.stripeClient.customers.listSources(customerId, {
        object: 'card',
      });
      const cardsList = cardObjs.data as unknown as Stripe.cards.ICard[];
      const card = convertFromToCard(cardsList) as unknown as Card[];

      await this.cacheStore.set(cacheKey, card, {ttl: 50});
      return card;
    } catch (e) {
      this.logger.error(e);
      throw new ApolloError(e);
    }
  }
}