Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
};
// 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}});
}
},
};
// 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();
}
},
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);
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.'
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.',
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()
);
export const buildValidationError = field => {
const ErrorType = createError('Functional', {
message: `Validation error for ${field}`,
data: { type: TYPE_BUSINESS, level: LEVEL_ERROR }
});
return new ErrorType();
};
export const ConstraintFailure = field => {
const ErrorType = createError('Functional', {
message: `Validation error for ${field}`,
data: { type: TYPE_BUSINESS }
});
return new ErrorType();
};
import { createError } from 'apollo-errors';
export const AuthorizationError = createError('AuthorizationError', {
message: 'You are not authorized.'
});
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', {