Closed nikoTM closed 2 years ago
When provided a faulty link that raises response code 500, the promise resolves with an empty file.
500
https://github.com/tobydeh/nativescript-download-progress/blob/b165d990dda6e8f1808970eb7fb8defac830c109/src/download-progress.ios.ts#L120 is being called regardless of the server response. In case of error being empty it resolves with the empty file, but the assumption of error being empty means request succeeded is not correct.
error
As a workaround, I modified else block to be this:
else
else { if (task && task.response && task.response.statusCode) { const statusCode = task.response.statusCode; if (statusCode < 200 || statusCode >= 400) { reject('Server responded with status code ' + statusCode); return; } } resolve(destinationFile); }
task.response is NSHTTPURLResponse
task.response
When provided a faulty link that raises response code
500
, the promise resolves with an empty file.https://github.com/tobydeh/nativescript-download-progress/blob/b165d990dda6e8f1808970eb7fb8defac830c109/src/download-progress.ios.ts#L120 is being called regardless of the server response. In case of
error
being empty it resolves with the empty file, but the assumption oferror
being empty means request succeeded is not correct.As a workaround, I modified
else
block to be this:task.response
is NSHTTPURLResponse