2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Moved error messages to "messages" hash

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

- As I've touched these files did a little refactor and changed where the error messages are stored to keep it up with our lates coding standard - having "messages" hash defined in the module storing all messages that have pottential for i18y in the future.
This commit is contained in:
Naz 2021-09-22 11:57:49 +02:00
parent ee43133dd9
commit ceb2b7e5ea
2 changed files with 13 additions and 4 deletions

View file

@ -1,6 +1,10 @@
const {DateTime} = require('luxon');
const {IncorrectUsageError} = require('@tryghost/errors');
const messages = {
invalidInterval: 'Invalid interval specified. Only "month" value is accepted.'
};
const SUPPORTED_INTERVALS = ['month'];
/**
* Calculates the start of the last period (billing, cycle, etc.) based on the start date
@ -23,7 +27,7 @@ const lastPeriodStart = (startDate, interval) => {
}
throw new IncorrectUsageError({
message: 'Invalid interval specified. Only "month" value is accepted.'
message: messages.invalidInterval
});
};

View file

@ -3,6 +3,11 @@ const config = require('./config');
const {IncorrectUsageError} = require('@tryghost/errors');
const _ = require('lodash');
const messages = {
missingErrorsConfig: `Config Missing: 'errors' is required.`,
noSubscriptionParameter: 'Attempted to setup a periodic max limit without a subscription'
};
class LimitService {
constructor() {
this.limits = {};
@ -21,7 +26,7 @@ class LimitService {
loadLimits({limits = {}, subscription, helpLink, db, errors}) {
if (!errors) {
throw new IncorrectUsageError({
message: `Config Missing: 'errors' is required.`
message: messages.missingErrorsConfig
});
}
@ -44,8 +49,8 @@ class LimitService {
this.limits[name] = new MaxLimit({name: name, config: limitConfig, helpLink, db, errors});
} else if (_.has(limitConfig, 'maxPeriodic')) {
if (subscription === undefined) {
throw new errors.IncorrectUsageError({
message: 'Attempted to setup a periodic max limit without a subscription'
throw new IncorrectUsageError({
message: messages.noSubscriptionParameter
});
}