rn-fetch-blob
rn-fetch-blob copied to clipboard
Response status code is 404 but RNFetchBlob.fetch calls `then` not `catch`
If I request a resource which does not exist, the module should see that the response code is an error (404), not save the content and throw an error.
However, this is not the case.
RNFetchBlob.fetch("GET", "http://google.com/this-is-not-a-file")
.then((res) => {
console.log("success", res);
})
.catch(error => {
console.log("error", error);
});
thankfully the response code is returned in res
so I can handle this at my end, but i still think this constitutes an error.
Such behaviour surprises me as well. I can add one note about the code in the file RNFetchBlobReq.java. There is implementation of the okhttp3.Callback there which for some reason assumes that onResponse method of okhttp3 lib means successful http response which is not true. I think that checking of http status code should be added there.
Assuming that the promise rejects on HTTP error statuses https://cameronnokes.com/blog/4-common-mistakes-front-end-developers-make-when-using-fetch/
It's fine if the promise resolves even when 404, but it also saves a broken file when path
is provided. Surely that makes no sense.