diff --git a/src/ImageLoader.js b/src/ImageLoader.js index 53e2ff7..d33a29f 100644 --- a/src/ImageLoader.js +++ b/src/ImageLoader.js @@ -78,10 +78,12 @@ export default class ImageLoader { } } }; - xhr.ontimeout = () => reject(`Timed out fetching ${src}`); xhr.responseType = 'blob'; if (this.options.imageTimeout) { - xhr.timeout = this.options.imageTimeout; + const timeout = this.options.imageTimeout; + xhr.timeout = timeout; + xhr.ontimeout = () => + reject(__DEV__ ? `Timed out (${timeout}ms) fetching ${src}` : ''); } xhr.open('GET', src, true); xhr.send(); @@ -122,6 +124,13 @@ export default class ImageLoader { resolve(img); }, 500); } + if (this.options.imageTimeout) { + const timeout = this.options.imageTimeout; + setTimeout( + () => reject(__DEV__ ? `Timed out (${timeout}ms) fetching ${src}` : ''), + timeout + ); + } }); this.cache[key] = diff --git a/src/index.js b/src/index.js index 6a841b6..1faf848 100644 --- a/src/index.js +++ b/src/index.js @@ -19,7 +19,7 @@ export type Options = { async: ?boolean, allowTaint: ?boolean, canvas: ?HTMLCanvasElement, - imageTimeout: ?number, + imageTimeout: number, proxy: ?string, removeContainer: ?boolean, scale: number,