mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Fixed IncorrectUsageError initialization
no issue - The error takes in an options object which should contain "message" property instead of a string
This commit is contained in:
parent
4f41c2a206
commit
1483a5c758
2 changed files with 11 additions and 6 deletions
|
@ -44,11 +44,11 @@ class MaxLimit extends Limit {
|
|||
super({name, error: config.error || '', helpLink, db, errors});
|
||||
|
||||
if (config.max === undefined) {
|
||||
throw new errors.IncorrectUsageError('Attempted to setup a max limit without a limit');
|
||||
throw new errors.IncorrectUsageError({message: 'Attempted to setup a max limit without a limit'});
|
||||
}
|
||||
|
||||
if (!config.currentCountQuery) {
|
||||
throw new errors.IncorrectUsageError('Attempted to setup a max limit without a current count query');
|
||||
throw new errors.IncorrectUsageError({message: 'Attempted to setup a max limit without a current count query'});
|
||||
}
|
||||
|
||||
this.currentCountQueryFn = config.currentCountQuery;
|
||||
|
@ -210,7 +210,7 @@ class AllowlistLimit extends Limit {
|
|||
super({name, error: config.error || '', helpLink, errors});
|
||||
|
||||
if (!config.allowlist || !config.allowlist.length) {
|
||||
throw new this.errors.IncorrectUsageError('Attempted to setup an allowlist limit without an allowlist');
|
||||
throw new this.errors.IncorrectUsageError({message: 'Attempted to setup an allowlist limit without an allowlist'});
|
||||
}
|
||||
|
||||
this.allowlist = config.allowlist;
|
||||
|
@ -231,7 +231,7 @@ class AllowlistLimit extends Limit {
|
|||
|
||||
async errorIfWouldGoOverLimit(metadata) {
|
||||
if (!metadata.value) {
|
||||
throw new this.errors.IncorrectUsageError('Attempted to check an allowlist limit without a value');
|
||||
throw new this.errors.IncorrectUsageError({message: 'Attempted to check an allowlist limit without a value'});
|
||||
}
|
||||
if (!this.allowlist.includes(metadata.value)) {
|
||||
throw this.generateError();
|
||||
|
@ -240,7 +240,7 @@ class AllowlistLimit extends Limit {
|
|||
|
||||
async errorIfIsOverLimit(metadata) {
|
||||
if (!metadata.value) {
|
||||
throw new this.errors.IncorrectUsageError('Attempted to check an allowlist limit without a value');
|
||||
throw new this.errors.IncorrectUsageError({message: 'Attempted to check an allowlist limit without a value'});
|
||||
}
|
||||
if (!this.allowlist.includes(metadata.value)) {
|
||||
throw this.generateError();
|
||||
|
|
|
@ -55,11 +55,14 @@ describe('Limit Service', function () {
|
|||
should.exist(err);
|
||||
should.exist(err.errorType);
|
||||
should.equal(err.errorType, 'IncorrectUsageError');
|
||||
err.message.should.match(/max limit without a limit/);
|
||||
}
|
||||
});
|
||||
|
||||
it('throws if initialized without a current count query', function () {
|
||||
const config = {};
|
||||
const config = {
|
||||
max: 100
|
||||
};
|
||||
|
||||
try {
|
||||
const limit = new MaxLimit({name: 'no accountability!', config, errors});
|
||||
|
@ -68,6 +71,7 @@ describe('Limit Service', function () {
|
|||
should.exist(err);
|
||||
should.exist(err.errorType);
|
||||
should.equal(err.errorType, 'IncorrectUsageError');
|
||||
err.message.should.match(/max limit without a current count query/);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -299,6 +303,7 @@ describe('Limit Service', function () {
|
|||
throw new Error('Should have failed earlier...');
|
||||
} catch (error) {
|
||||
error.errorType.should.equal('IncorrectUsageError');
|
||||
error.message.should.match(/allowlist limit without an allowlist/);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue