From ceb2b7e5ea35a5f18cfec16b07f05b395c40858e Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 22 Sep 2021 11:57:49 +0200 Subject: [PATCH] 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. --- ghost/limit-service/lib/date-utils.js | 6 +++++- ghost/limit-service/lib/limit-service.js | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ghost/limit-service/lib/date-utils.js b/ghost/limit-service/lib/date-utils.js index 6798c4ec21..cc91f34019 100644 --- a/ghost/limit-service/lib/date-utils.js +++ b/ghost/limit-service/lib/date-utils.js @@ -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 }); }; diff --git a/ghost/limit-service/lib/limit-service.js b/ghost/limit-service/lib/limit-service.js index 5996d68591..4fb90f542d 100644 --- a/ghost/limit-service/lib/limit-service.js +++ b/ghost/limit-service/lib/limit-service.js @@ -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 }); }