packager: GlobalTransformCache: ignore errors related to fetching

Reviewed By: davidaurelio

Differential Revision: D4745584

fbshipit-source-id: 2c9b2451d3525c90308fb88784945462cd827d1f
This commit is contained in:
Jean Lauliac 2017-03-21 05:54:06 -07:00 committed by Facebook Github Bot
parent 5c128ad049
commit 4cbb64521a
1 changed files with 14 additions and 2 deletions

View File

@ -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<CachedResult> {
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;