0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Removed usage of raw Error class

refs https://github.com/TryGhost/Team/issues/879
This commit is contained in:
Fabien O'Carroll 2021-07-14 14:11:33 +01:00
parent d51fdc3f4a
commit 3e1084905e
5 changed files with 15 additions and 10 deletions

View file

@ -1,3 +1,5 @@
const {IncorrectUsageError} = require('@tryghost/errors');
/**
* @typedef { import('nodemailer').Transporter } MailTransporter
* @typedef { import('nodemailer').SentMessageInfo } SentMessageInfo
@ -29,7 +31,7 @@ class MagicLink {
*/
constructor(options) {
if (!options || !options.transporter || !options.tokenProvider || !options.getSigninURL) {
throw new Error('Missing options. Expects {transporter, tokenProvider, getSigninURL}');
throw new IncorrectUsageError('Missing options. Expects {transporter, tokenProvider, getSigninURL}');
}
this.transporter = options.transporter;
this.tokenProvider = options.tokenProvider;

View file

@ -1,3 +1,4 @@
const {UnauthorizedError} = require('@tryghost/errors');
const jwt = require('jsonwebtoken');
/**
@ -42,7 +43,7 @@ module.exports = class JWTTokenProvider {
});
if (!claims || typeof claims === 'string') {
throw new Error();
throw new UnauthorizedError();
}
return claims;

View file

@ -1,4 +1,4 @@
const {UpdateCollisionError} = require('@tryghost/errors');
const {UpdateCollisionError, NotFoundError, MethodNotAllowedError} = require('@tryghost/errors');
/**
* @typedef {object} ProductModel
@ -87,7 +87,7 @@ class ProductRepository {
return await this._Product.findOne({slug: data.slug}, options);
}
throw new Error('Missing id, slug, stripe_product_id or stripe_price_id from data');
throw new NotFoundError('Missing id, slug, stripe_product_id or stripe_price_id from data');
}
/**
@ -469,7 +469,7 @@ class ProductRepository {
}
async destroy() {
throw new Error('Cannot destroy products, yet...');
throw new MethodNotAllowedError('Cannot destroy products, yet...');
}
}

View file

@ -1,3 +1,4 @@
const {VersionMismatchError} = require('@tryghost/errors');
const debug = require('@tryghost/debug')('services/stripe');
const Stripe = require('stripe').Stripe;
const LeakyBucket = require('leaky-bucket');
@ -293,7 +294,7 @@ module.exports = class StripeAPIService {
enabled_events: events
});
if (webhook.api_version !== STRIPE_API_VERSION) {
throw new Error('Webhook has incorrect api_version');
throw new VersionMismatchError('Webhook has incorrect api_version');
}
debug(`updateWebhook(${id}, ${url}) -> Success`);
return webhook;

View file

@ -3,7 +3,8 @@ const createCookies = require('cookies');
const debug = require('@tryghost/debug')('members-ssr');
const {
BadRequestError
BadRequestError,
IncorrectUsageError
} = require('@tryghost/ignition-errors');
/**
@ -52,13 +53,13 @@ class MembersSSR {
} = options;
if (!getMembersApi) {
throw new Error('Missing option getMembersApi');
throw new IncorrectUsageError('Missing option getMembersApi');
}
this._getMembersApi = getMembersApi;
if (!cookieKeys) {
throw new Error('Missing option cookieKeys');
throw new IncorrectUsageError('Missing option cookieKeys');
}
this.sessionCookieName = cookieName;
@ -287,7 +288,7 @@ class MembersSSR {
*/
module.exports = function create(options) {
if (!options) {
throw new Error('Must pass options');
throw new IncorrectUsageError('Must pass options');
}
return new MembersSSR(options);
};