rn-fetch-blob icon indicating copy to clipboard operation
rn-fetch-blob copied to clipboard

Response status code is 404 but RNFetchBlob.fetch calls `then` not `catch`

Open pstanton opened this issue 6 years ago • 4 comments

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);
});

pstanton avatar Aug 20 '18 05:08 pstanton

thankfully the response code is returned in res so I can handle this at my end, but i still think this constitutes an error.

pstanton avatar Aug 20 '18 05:08 pstanton

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.

PlatonSotnykov avatar Jun 12 '19 08:06 PlatonSotnykov

Assuming that the promise rejects on HTTP error statuses https://cameronnokes.com/blog/4-common-mistakes-front-end-developers-make-when-using-fetch/

vasylnahuliak avatar Feb 25 '20 10:02 vasylnahuliak

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.

SirCameron avatar May 25 '23 10:05 SirCameron