Closed chadwilken closed 7 years ago
I'm not sure I'm following, wouldn't calling .catch(fn)
on the return value of RNS3.put
handle any rejected promises, even if they're initially rejected before the put
method returns?
I would expect behavior like I see in my console:
Do you have any super simple reproducible cases you could share?
So we have
const file = {
uri: `file://${path}`,
name: `${photo.uuid}.jpg`,
type: 'image/jpg',
};
const options = {
bucket: 'our-bucket',
region: 'us-east-1',
accessKey: ACCESS_KEY,
secretKey: SECRET_ACCESS_KEY,
};
RNS3.put(file, options)
.then((response) => {
const { postResponse } = response.body;
if (response.status === 201) {
// Make an api call with the returned URI
}
})
.catch((error) => { console.log(error); }); // The catch doesn't get called
The catch
wasn't getting called and logging to the console. I added a check to see if the device has internet above it and it seems to work now.
I think the reason that the catch doesn't get called is that when you call put
it immediately opens, sets the file, and then sends the request. If the device is offline I don't think the callback gets called. Am I way off base here?
Cool, I can try replicating that when I get a moment and fix it. #16 might be related too (the onerror
piece).
Just released a new version and I am seeing catch
getting called correctly, so going to close this.
Currently in the
Request
class you have the option for acatch
, the problem is that theRNS3
class creates and then immediately callssend
on theXMLHTTPRequest
, which if there is an issue will fail before the return, this prevents thecatch
method a user might add from being called.