mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
packager: GlobalTransformCache: ignore errors related to fetching
Reviewed By: davidaurelio Differential Revision: D4745584 fbshipit-source-id: 2c9b2451d3525c90308fb88784945462cd827d1f
This commit is contained in:
committed by
Facebook Github Bot
parent
5c128ad049
commit
4cbb64521a
@@ -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
|
* 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.
|
* we expect a result to be. So we need to verify carefully the data.
|
||||||
@@ -171,6 +178,8 @@ class GlobalTransformCache {
|
|||||||
_profileSet: TransformProfileSet;
|
_profileSet: TransformProfileSet;
|
||||||
_store: ?KeyResultStore;
|
_store: ?KeyResultStore;
|
||||||
|
|
||||||
|
static FetchFailedError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For using the global cache one needs to have some kind of central key-value
|
* 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
|
* store that gets prefilled using keyOf() and the transformed results. The
|
||||||
@@ -214,12 +223,13 @@ class GlobalTransformCache {
|
|||||||
static async _fetchResultFromURI(uri: string): Promise<CachedResult> {
|
static async _fetchResultFromURI(uri: string): Promise<CachedResult> {
|
||||||
const response = await fetch(uri, {method: 'GET', timeout: 8000});
|
const response = await fetch(uri, {method: 'GET', timeout: 8000});
|
||||||
if (response.status !== 200) {
|
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 unvalidatedResult = await response.json();
|
||||||
const result = validateCachedResult(unvalidatedResult);
|
const result = validateCachedResult(unvalidatedResult);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
throw new Error('Server returned invalid result.');
|
throw new FetchFailedError('Server returned invalid result.');
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -260,4 +270,6 @@ class GlobalTransformCache {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GlobalTransformCache.FetchFailedError = FetchFailedError;
|
||||||
|
|
||||||
module.exports = GlobalTransformCache;
|
module.exports = GlobalTransformCache;
|
||||||
|
|||||||
Reference in New Issue
Block a user