From b6787c3df912c733e3d6f6c647e41d14bf592b59 Mon Sep 17 00:00:00 2001 From: Mark Adamcin Date: Tue, 24 May 2022 12:21:31 -0700 Subject: [PATCH 1/3] ASSETS-8997 add serviceoverload error reason --- lib/errors.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/errors.js b/lib/errors.js index 6aa605e..d947395 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" }); @@ -74,7 +75,6 @@ class ClientError extends Error { } } - // The requested format is unsupported. // To throw error: throw new RenditionFormatUnsupportedError(`The requested format is unsupported`); class RenditionFormatUnsupportedError extends ClientError { @@ -121,6 +121,18 @@ class RenditionTooLarge extends ClientError { } } +/** + * ServiceOverLoad error: Error thrown by actions when a backend API is reporting too many requests. + * @param message Error message + * @param location Error location, a short greppable string describing the exception location (e.g. "sdk_rendition_upload") + */ + class ServiceOverLoadError extends ClientError { + constructor(message) { + super(message, "ServiceOverLoadError", Reason.ServiceOverLoad); + + Error.captureStackTrace(this, ServiceOverLoadError); + } +} module.exports = { GenericError, @@ -131,5 +143,6 @@ module.exports = { SourceUnsupportedError, SourceCorruptError, RenditionTooLarge, - ArgumentError + ArgumentError, + ServiceOverLoadError }; From a8010dabb9f9f058f2d219b3c444fe315603a4eb Mon Sep 17 00:00:00 2001 From: Mark Adamcin Date: Tue, 24 May 2022 12:31:34 -0700 Subject: [PATCH 2/3] ASSETS-8997 add unit test for serviceoverload --- lib/errors.js | 3 ++- test/errors.test.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/errors.js b/lib/errors.js index d947395..64d685d 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -75,6 +75,7 @@ class ClientError extends Error { } } + // The requested format is unsupported. // To throw error: throw new RenditionFormatUnsupportedError(`The requested format is unsupported`); class RenditionFormatUnsupportedError extends ClientError { @@ -126,7 +127,7 @@ class RenditionTooLarge extends ClientError { * @param message Error message * @param location Error location, a short greppable string describing the exception location (e.g. "sdk_rendition_upload") */ - class ServiceOverLoadError extends ClientError { +class ServiceOverLoadError extends ClientError { constructor(message) { super(message, "ServiceOverLoadError", Reason.ServiceOverLoad); 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); + } + }); }); From 42ac6ae825b7b16bce808fab9510ba97f1959d85 Mon Sep 17 00:00:00 2001 From: Mark Adamcin Date: Tue, 24 May 2022 12:37:02 -0700 Subject: [PATCH 3/3] ASSETS-8997 corrected class description --- lib/errors.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/errors.js b/lib/errors.js index 64d685d..f2a04c2 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -122,11 +122,7 @@ class RenditionTooLarge extends ClientError { } } -/** - * ServiceOverLoad error: Error thrown by actions when a backend API is reporting too many requests. - * @param message Error message - * @param location Error location, a short greppable string describing the exception location (e.g. "sdk_rendition_upload") - */ +// Worker encountered upstream API rate limiting. Client may resubmit request after some time. class ServiceOverLoadError extends ClientError { constructor(message) { super(message, "ServiceOverLoadError", Reason.ServiceOverLoad);