diff --git a/core/token-pooling/token-pool.js b/core/token-pooling/token-pool.js index 5061c8dbf6c168ebcb009870cfdcbec5cff619f3..98fecae6c188a4f2e2c9e557345fd7bb81df8f7f 100644 --- a/core/token-pooling/token-pool.js +++ b/core/token-pooling/token-pool.js @@ -5,6 +5,7 @@ const crypto = require('crypto') const PriorityQueue = require('priorityqueuejs') +const { Inaccessible } = require('../base-service/errors') /** * Compute a one-way hash of the input string. @@ -265,7 +266,10 @@ class TokenPool { } } - throw Error('Token pool is exhausted') + throw new Inaccessible({ + underlyingError: Error('Token pool is exhausted'), + prettyMessage: 'no tokens available', + }) } /** diff --git a/core/token-pooling/token-pool.spec.js b/core/token-pooling/token-pool.spec.js index 1c62f2707f321c9d287777a10c457e8eb2eeb878..4da02975284060146b55fe6fd240fc8a8db5fa9c 100644 --- a/core/token-pooling/token-pool.spec.js +++ b/core/token-pooling/token-pool.spec.js @@ -3,12 +3,13 @@ const { expect } = require('chai') const sinon = require('sinon') const times = require('lodash.times') +const { Inaccessible } = require('../base-service/errors') const { Token, TokenPool } = require('./token-pool') function expectPoolToBeExhausted(pool) { expect(() => { pool.next() - }).to.throw(Error, /^Token pool is exhausted$/) + }).to.throw(Inaccessible, /^Inaccessible: Token pool is exhausted$/) } describe('The token pool', function() {