From 3dc48577472bc3b4bf1c20b13153f4ff367742f1 Mon Sep 17 00:00:00 2001 From: Paul Melnikow <email@paulmelnikow.com> Date: Mon, 6 Apr 2020 13:16:31 -0400 Subject: [PATCH] When token pool is empty, surface the error to the badge consumer Should provide better debuggability in self-hosting cases like #4862 but also on the production server. --- core/token-pooling/token-pool.js | 6 +++++- core/token-pooling/token-pool.spec.js | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/token-pooling/token-pool.js b/core/token-pooling/token-pool.js index 5061c8dbf6..98fecae6c1 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 1c62f2707f..4da0297528 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() { -- GitLab