Removed use of native JS Error objects

refs https://linear.app/tryghost/issue/CORE-49/fix-errors-in-utils-repo-limit-service

- The latest ESLint rules forbid use of native JS errors, updated the codebase before bumping the ESLint version
This commit is contained in:
Naz 2021-09-22 11:32:02 +02:00
parent a28a2a23a5
commit 2b82d2afce
3 changed files with 5 additions and 2 deletions

View File

@ -1,4 +1,5 @@
const {DateTime} = require('luxon');
const {IncorrectUsageError} = require('@tryghost/errors');
const SUPPORTED_INTERVALS = ['month'];
/**
@ -21,7 +22,7 @@ const lastPeriodStart = (startDate, interval) => {
return lastPeriodStartDate.toISO();
}
throw new Error('Invalid interval specified. Only "month" value is accepted.');
throw new IncorrectUsageError('Invalid interval specified. Only "month" value is accepted.');
};
module.exports = {

View File

@ -1,5 +1,6 @@
const {MaxLimit, MaxPeriodicLimit, FlagLimit, AllowlistLimit} = require('./limit');
const config = require('./config');
const {IncorrectUsageError} = require('@tryghost/errors');
const _ = require('lodash');
class LimitService {
@ -19,7 +20,7 @@ class LimitService {
*/
loadLimits({limits = {}, subscription, helpLink, db, errors}) {
if (!errors) {
throw new Error(`Config Missing: 'errors' is required.`);
throw new IncorrectUsageError(`Config Missing: 'errors' is required.`);
}
this.errors = errors;

View File

@ -26,6 +26,7 @@
"sinon": "11.0.0"
},
"dependencies": {
"@tryghost/errors": "^0.2.13",
"lodash": "^4.17.21",
"luxon": "^1.26.0"
}