Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Catching receiver.write error #34

Open
madisongiles opened this issue Jul 7, 2020 · 0 comments
Open

Catching receiver.write error #34

madisongiles opened this issue Jul 7, 2020 · 0 comments

Comments

@madisongiles
Copy link

madisongiles commented Jul 7, 2020

Hi team, thanks so much for this adapter I've had a lot of success with it except for one issue. I'm having trouble catching an error triggered by the receiver.write function. When an error occurs it completely stops my Sails app. I've tried wrapping the method in try/catch blocks and setting up promises but I can't figure it out.

My code is:

const adapter = require('skipper-better-s3')(sails.config.uploads.s3);
const receiver = adapter.receive(receiverParams);

receiver.write(localFile, (err) => {
    if (err) {
        sails.log.error('Error uploading to Amazon S3:', err);
    } else if ( localFile.extra && localFile.extra.key ) {
        sails.log.info('Uploaded file to Amazon S3: ' + localFile.extra.key);
    }
});

You can reliably get an error firing by setting the s3 region to a random string.

I did have a similar problem with the adapter.read function causing my app to crash if there was no matching key on S3 matching the file descriptor, however I was able to resolve this by stringing on an "on('error')" function. However this doesn't work to resolve the issue I'm having with receiver.write :(

adapter.read(fd).on('error', (err) => {
  console.log(err);
});

I'm a bit of a beginner so it's probably really obvious what I'm doing wrong. Is anyone able to help?

Thanks so much,
Madison

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant