File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -104,10 +104,27 @@ module.exports = {
104104 let status = Math . floor ( res . respInfo . status / 100 ) ;
105105 if ( status !== 2 ) {
106106 // TODO - log / return error?
107- throw new Error ( 'Download failed' ) ;
107+ return Promise . reject ( ) ;
108108 }
109- // the download is complete and rename the temporary file
110- return fs . mv ( tmpFile , toFile ) ;
109+
110+ return RNFetchBlob . fs . stat ( tmpFile )
111+ . then ( fileStats => {
112+ // Verify if the content was fully downloaded!
113+ if ( res . respInfo . headers [ 'Content-Length' ] && res . respInfo . headers [ 'Content-Length' ] != fileStats . size ) {
114+ return Promise . reject ( ) ;
115+ }
116+
117+ // the download is complete and rename the temporary file
118+ return fs . mv ( tmpFile , toFile ) ;
119+ } ) ;
120+
121+
122+ } )
123+ . catch ( error => {
124+ // cleanup. will try re-download on next CachedImage mount.
125+ this . deleteFile ( tmpFile ) ;
126+ delete activeDownloads [ toFile ] ;
127+ return Promise . reject ( 'Download failed' ) ;
111128 } )
112129 . then ( ( ) => {
113130 // cleanup
You can’t perform that action at this time.
0 commit comments