Fixed error "swallowing"

no issue

- I've discovered the "IncorrectUsageError" error was silently swallowed and the method returned a false positibe when an allowlist limit type was called with incorrect parameters
- In cases like this it's best to surface the real error early otherwise the logic might produce unsafe results!
This commit is contained in:
Naz 2021-05-21 14:02:35 +04:00
parent 9632e98dd2
commit f0a5fc975c
2 changed files with 24 additions and 0 deletions

View File

@ -69,6 +69,8 @@ class LimitService {
if (error instanceof this.errors.HostLimitError) {
return true;
}
throw error;
}
}
@ -84,6 +86,8 @@ class LimitService {
if (error instanceof this.errors.HostLimitError) {
return true;
}
throw error;
}
}

View File

@ -303,5 +303,25 @@ describe('Limit Service', function () {
(await limitService.checkIfAnyOverLimit()).should.be.false();
});
it('Throws an error when an allowlist limit is checked', async function () {
const limitService = new LimitService();
let limits = {
// TODO: allowlist type of limits doesn't have "checkIsOverLimit" implemented yet!
customThemes: {
allowlist: ['casper', 'dawn', 'lyra']
}
};
limitService.loadLimits({limits, errors});
try {
await limitService.checkIfAnyOverLimit();
should.fail(limitService, 'Should have errored');
} catch (err) {
err.message.should.eql(`Cannot read property 'value' of undefined`);
}
});
});
});