Permalink
Browse files

packager: GlobalTransformCache: ignore errors related to fetching

Reviewed By: davidaurelio

Differential Revision: D4745584

fbshipit-source-id: 2c9b2451d3525c90308fb88784945462cd827d1f
  • Loading branch information...
jeanlauliac authored and facebook-github-bot committed Mar 21, 2017
1 parent 5c128ad commit 4cbb64521a9a3fbbef9cf741314060ef71f07357
Showing with 14 additions and 2 deletions.
  1. +14 −2 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<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;

0 comments on commit 4cbb645

Please sign in to comment.