diff --git a/lib/errors.js b/lib/errors.js index 6aa605e..f2a04c2 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -21,7 +21,8 @@ const Reason = Object.freeze({ RenditionFormatUnsupported: "RenditionFormatUnsupported", SourceUnsupported: "SourceUnsupported", SourceCorrupt: "SourceCorrupt", - RenditionTooLarge: "RenditionTooLarge" + RenditionTooLarge: "RenditionTooLarge", + ServiceOverLoad: "ServiceOverLoad" }); @@ -121,6 +122,14 @@ class RenditionTooLarge extends ClientError { } } +// Worker encountered upstream API rate limiting. Client may resubmit request after some time. +class ServiceOverLoadError extends ClientError { + constructor(message) { + super(message, "ServiceOverLoadError", Reason.ServiceOverLoad); + + Error.captureStackTrace(this, ServiceOverLoadError); + } +} module.exports = { GenericError, @@ -131,5 +140,6 @@ module.exports = { SourceUnsupportedError, SourceCorruptError, RenditionTooLarge, - ArgumentError + ArgumentError, + ServiceOverLoadError }; diff --git a/test/errors.test.js b/test/errors.test.js index 0443a55..3e99ec0 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -21,7 +21,8 @@ const { SourceFormatUnsupportedError, SourceUnsupportedError, SourceCorruptError, - RenditionTooLarge + RenditionTooLarge, + ServiceOverLoadError } = require('../lib/errors'); describe("errors", function() { @@ -98,4 +99,16 @@ describe("errors", function() { assert.equal(e.reason, Reason.RenditionTooLarge); } }); + + it("ServiceOverLoadError", function() { + try { + throw new ServiceOverLoadError("too many requests"); + } catch (e) { + assert.ok(e instanceof ClientError); + assert.ok(e instanceof ServiceOverLoadError); + assert.equal(e.name, "ServiceOverLoadError"); + assert.equal(e.message, "too many requests"); + assert.equal(e.reason, Reason.ServiceOverLoad); + } + }); });