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;