mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03: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:
parent
ee43133dd9
commit
ceb2b7e5ea
@ -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
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user