Skip to content

Commit

Permalink
properly fail when response status code is not 20*
Browse files Browse the repository at this point in the history
  • Loading branch information
kfiroo committed Apr 20, 2017
1 parent 08a0427 commit e6efa26
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ImageCacheProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ function downloadImage(fromUrl, toFile, headers = {}) {
RNFatchBlob
.config({path: toFile})
.fetch('GET', fromUrl, headers)
.then(res => resolve(toFile))
.catch(err =>
deleteFile(toFile)
.then(() => reject(err))
)
.then(res => {
if (Math.floor(res.respInfo.status / 100) !== 2) {
throw new Error('Failed to successfully download image');
}
resolve(toFile);
})
.catch(err => {
return deleteFile(toFile)
.then(() => reject(err));
})
.finally(() => {
// cleanup
delete activeDownloads[toFile];
Expand Down Expand Up @@ -153,6 +158,8 @@ function runPrefetchTask(prefetcher, options) {
return getCachedImagePath(url, options)
// if not found download
.catch(() => cacheImage(url, options))
// allow prefetch task to fail without terminating other prefetch tasks
.catch(_.noop)
// then run next task
.then(() => runPrefetchTask(prefetcher, options));
}
Expand Down

0 comments on commit e6efa26

Please sign in to comment.