Rn-fetch-blob: Response status code is 404 but RNFetchBlob.fetch calls `then` not `catch`

Created on 20 Aug 2018  路  3Comments  路  Source: joltup/rn-fetch-blob

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

Most helpful comment

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

All 3 comments

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/

Was this page helpful?
0 / 5 - 0 ratings