react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

Use getErrorStream() if status code is >= 400 in uploadFiles

Open denichodev opened this issue 5 years ago • 4 comments

The current state of the Java Uploader is to always use connection.getInputStream() for any response in the RNFS.uploadFiles.

This behavior makes handling the different status code or any error message inside the response body impossible.

In my use case, the server would send status code 500 if I uploaded the wrong file type, but if we use connection.getInputStream() when the server returns >= 400 status code, ENOENT error will happen (see here).

To fix this, we use connection.getErrorStream() whenever the server returns >= 400 status code.

Disclaimer: I am not experienced in Java programming, please help me to review or improve anything there is to improve.

denichodev avatar Oct 26 '20 17:10 denichodev

Can you help checking this @itinance? Thanks!

denichodev avatar Oct 26 '20 17:10 denichodev

Any update on this? I cannot upload photos to Cloudinary.

psamim avatar Nov 09 '20 11:11 psamim

@psamim You can use patch-package to modify installed node modules before this PR merged (I doubt it will be merged soon).

Anyway, looking at this issue https://github.com/itinance/react-native-fs/issues/755, there might be a problem within the code, this PR only handles non 200 response properly.

denichodev avatar Nov 09 '20 17:11 denichodev

@itinance Any update on this PR ? Any error from the back-end throw an ENOENT which doesn't allow good error management (400, 401, 403, 409, 429, ...)

Dallas62 avatar Oct 24 '24 22:10 Dallas62