From 4cbb64521a9a3fbbef9cf741314060ef71f07357 Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Tue, 21 Mar 2017 05:54:06 -0700 Subject: [PATCH] packager: GlobalTransformCache: ignore errors related to fetching Reviewed By: davidaurelio Differential Revision: D4745584 fbshipit-source-id: 2c9b2451d3525c90308fb88784945462cd827d1f --- packager/src/lib/GlobalTransformCache.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packager/src/lib/GlobalTransformCache.js b/packager/src/lib/GlobalTransformCache.js index b74a1981c..79a169ed2 100644 --- a/packager/src/lib/GlobalTransformCache.js +++ b/packager/src/lib/GlobalTransformCache.js @@ -145,6 +145,13 @@ class TransformProfileSet { } } +class FetchFailedError extends Error { + constructor(message) { + super(); + this.message = message; + } +} + /** * For some reason the result stored by the server for a key might mismatch what * we expect a result to be. So we need to verify carefully the data. @@ -171,6 +178,8 @@ class GlobalTransformCache { _profileSet: TransformProfileSet; _store: ?KeyResultStore; + static FetchFailedError; + /** * For using the global cache one needs to have some kind of central key-value * store that gets prefilled using keyOf() and the transformed results. The @@ -214,12 +223,13 @@ class GlobalTransformCache { static async _fetchResultFromURI(uri: string): Promise { const response = await fetch(uri, {method: 'GET', timeout: 8000}); if (response.status !== 200) { - throw new Error(`Unexpected HTTP status: ${response.status} ${response.statusText} `); + const msg = `Unexpected HTTP status: ${response.status} ${response.statusText} `; + throw new FetchFailedError(msg); } const unvalidatedResult = await response.json(); const result = validateCachedResult(unvalidatedResult); if (result == null) { - throw new Error('Server returned invalid result.'); + throw new FetchFailedError('Server returned invalid result.'); } return result; } @@ -260,4 +270,6 @@ class GlobalTransformCache { } +GlobalTransformCache.FetchFailedError = FetchFailedError; + module.exports = GlobalTransformCache;