How to use the apollo-server-koa.UserInputError function in apollo-server-koa

To help you get started, we’ve selected a few apollo-server-koa 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 fullstack-build / fullstack-one / packages / graphql / lib / koaMiddleware.ts View on Github external
return handleGenericError(ValidationError, "ValidationError: Details hidden.");
    }
    if (_.get(error, "name", null) === "UserInputError") {
      return handleGenericError(UserInputError, "UserInputError: Details hidden.");
    }
    if (_.get(error, "name", null) === "AuthenticationError") {
      return handleGenericError(AuthenticationError, "AuthenticationError: Details hidden.");
    }
    if (_.get(error, "name", null) === "ForbiddenError") {
      return handleGenericError(ForbiddenError, "ForbiddenError: Details hidden.");
    }

    // Try to map other errors to Apollo predefined errors. Useful when writing pg-functions which cannot return a specific Error Object
    if (error.message.indexOf("AUTH.THROW.USER_INPUT_ERROR") >= 0) {
      logger.trace(error);
      return new UserInputError("Bad user input.");
    }
    if (error.message.indexOf("AUTH.THROW.AUTHENTICATION_ERROR") >= 0) {
      logger.trace(error);
      return new AuthenticationError("Authentication required.");
    }
    if (error.message.indexOf("AUTH.THROW.FORBIDDEN_ERROR") >= 0) {
      logger.trace(error);
      return new ForbiddenError("Access forbidden.");
    }

    if (_.get(error, "name", null) === "ApolloError") {
      return handleGenericError(ApolloError, "ApolloError: Details hidden.");
    }
    if (_.get(error, "name", null) === "GraphQLError") {
      return handleGenericError(GraphQLError, "GraphQLError: Details hidden.");
    }