How to use apollo-errors - 10 common examples

To help you get started, we’ve selected a few apollo-errors 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 VulcanJS / Vulcan / packages / vulcan-newsletter / lib / server / integrations / mailchimp.js View on Github external
};
        // subscribe user
        const subscribe = callSyncAPI('lists', 'subscribe', subscribeOptions);
        return {result: 'subscribed', ...subscribe};
      } catch (error) {
        console.log(error)
        let name;
        const message = error.message;
        if (error.code == 214) {
          name = 'has_unsubscribed';
        } else if (error.code == 214) {
          name = 'already_subscribed';
        } else {
          name = 'subscription_failed';
        }
        const NewsletterError = createError(name, { message });
        throw new NewsletterError({ data: {path: 'newsletter_subscribeToNewsletter', message}});
      }
    },
github LessWrong2 / Lesswrong2 / packages / vulcan-newsletter / lib / server / integrations / mailchimp.js View on Github external
};
        // subscribe user
        const subscribe = callSyncAPI('lists', 'subscribe', subscribeOptions);
        return {result: 'subscribed', ...subscribe};
      } catch (error) {
        console.log(error)
        let name, message;
        if (error.code == 214) {
          name = 'has_unsubscribed';
        } else if (error.code == 214) {
          name = 'already_subscribed';
        } else {
          name = 'subscription_failed';
          message = error.message;
        }
        const NewsletterError = createError(name, { message });
        throw new NewsletterError();
      }
    },
github VulcanJS / Vulcan-Starter / packages / example-forum / lib / server / posts / callbacks / validation.js View on Github external
function PostsNewRateLimit (post, user) {

  if(!Users.isAdmin(user)){

    var timeSinceLastPost = Users.timeSinceLast(user, Posts),
      numberOfPostsInPast24Hours = Users.numberOfItemsInPast24Hours(user, Posts),
      postInterval = Math.abs(parseInt(getSetting('forum.postInterval', 30))),
      maxPostsPer24Hours = Math.abs(parseInt(getSetting('forum.maxPostsPerDay', 5)));

    // check that user waits more than X seconds between posts
    if(timeSinceLastPost < postInterval){
      const RateLimitError = createError('posts.rate_limit_error', {message: 'posts.rate_limit_error'});
      throw new RateLimitError({data: {break: true, id: 'posts.rate_limit_error', properties: { value: postInterval-timeSinceLastPost }}});

    }
    // check that the user doesn't post more than Y posts per day
    if(numberOfPostsInPast24Hours >= maxPostsPer24Hours){
      const RateLimitError = createError('posts.max_per_day', {message: 'posts.max_per_day'});
      throw new RateLimitError({data: {break: true, id: 'posts.max_per_day', properties: { value: maxPostsPer24Hours }}});
    }
  }

  return post;
}
addCallback('posts.new.validate', PostsNewRateLimit);
github Volst / graphql-authentication / packages / graphql-authentication / src / errors.ts View on Github external
message: 'Not all required fields are filled in.'
});

export const InvalidEmailError = createError('InvalidEmailError', {
  message: 'Given email is invalid.'
});

export const ResetTokenExpiredError = createError('ResetTokenExpiredError', {
  message: 'resetToken expired.'
});

export const PasswordTooShortError = createError('PasswordTooShortError', {
  message: 'Password is too short.'
});

export const UserNotFoundError = createError('UserNotFoundError', {
  message: 'No user found.'
});

export const InvalidInviteTokenError = createError('InvalidInviteTokenError', {
  message: 'inviteToken is invalid.'
});

export const InvalidEmailConfirmToken = createError(
  'InvalidEmailConfirmToken',
  {
    message: 'emailConfirmToken is invalid.'
  }
);

export const UserEmailExistsError = createError('UserEmailExistsError', {
  message: 'User already exists with this email.'
github awesome-graphql-space / server-nestjs / src / common / apollo-errors / index.ts View on Github external
message: 'No connection found.',
});

export const InvalidEmailError = createError('InvalidEmailError', {
  message: 'Provided email is invalid.',
});

export const ResetTokenExpiredError = createError('ResetTokenExpiredError', {
  message: 'resetToken expired.',
});

export const PasswordTooShortError = createError('PasswordTooShortError', {
  message: 'Password is too short.',
});

export const UserNotFoundError = createError('UserNotFoundError', {
  message: 'No user found.',
});

export const InvalidInviteTokenError = createError('InvalidInviteTokenError', {
  message: 'inviteToken is invalid.',
});

export const InvalidEmailConfirmToken = createError(
  'InvalidEmailConfirmToken',
  {
    message: 'emailConfirmToken is invalid.',
  },
);

export const UserEmailExistsError = createError('UserEmailExistsError', {
  message: 'User already exists with this email.',
github hajocava / Graphql-Template / server / src / config / errors / baseResolver.js View on Github external
import { createResolver } from 'apollo-resolvers'
import { createError, isInstance } from 'apollo-errors'

const UnknownError = createError('UnknownError', {
    message: 'An unknown error has occurred! Please try again later'
});

export const baseResolver = createResolver(
    null,
    (root, args, context, error) => isInstance(error) ? error : new UnknownError()
);
github OpenCTI-Platform / opencti / opencti-platform / opencti-graphql / src / config / errors.js View on Github external
export const buildValidationError = field => {
  const ErrorType = createError('Functional', {
    message: `Validation error for ${field}`,
    data: { type: TYPE_BUSINESS, level: LEVEL_ERROR }
  });
  return new ErrorType();
};
github OpenCTI-Platform / opencti / opencti-graphql / src / config / errors.js View on Github external
export const ConstraintFailure = field => {
  const ErrorType = createError('Functional', {
    message: `Validation error for ${field}`,
    data: { type: TYPE_BUSINESS }
  });
  return new ErrorType();
};
github freeCodeCamp / open-api / src / graphql / errors / index.js View on Github external
import { createError } from 'apollo-errors';

export const AuthorizationError = createError('AuthorizationError', {
  message: 'You are not authorized.'
});
github opencollective / opencollective-api / server / graphql / errors.js View on Github external
import { createError } from 'apollo-errors';

export const Unauthorized = createError('Unauthorized', {
  message: 'You need to be authenticated to perform this action',
});

export const Forbidden = createError('Forbidden', {
  message: 'You are authenticated but forbidden to perform this action',
});

export const RateLimitExceeded = createError('RateLimitExceeded', {
  message: 'Rate limit exceeded',
});

export const ValidationFailed = createError('ValidationFailed', {
  message: 'Please verify the input data',
});

export const NotFound = createError('NotFound', {

apollo-errors

Machine-readable custom errors for Apollostack's GraphQL server

MIT
Latest version published 7 years ago

Package Health Score

53 / 100
Full package analysis

Popular apollo-errors functions