spmjs / node-scp2

[MAINTAINER WANTED] A pure javascript scp program based on ssh2.
384 stars 96 forks source link

Thrown error when destination folder incorrect or wrong permissions #80

Open NicolasDucom opened 7 years ago

NicolasDucom commented 7 years ago

Hi! I'm currently having a bit of trouble concerning my upload function :

    client.on('error', function(err) {
        return res.status(500).json({
            message: 'Error when sending image to media server',
            error: err
        });
    });

    client.upload(req.file.path, '/home2/myhome/'+image.storedName, function (err) {
        if (err) {
            return res.status(500).json({
                message: 'Error when sending image to media server',
                error: err
            });
        }

        image.fullUrl = config.mediaURL + image.storedName;
        image.save(function (err, image) {
            if (err) {
                return res.status(500).json({
                    message: 'Error when saving image',
                    error: err
                });
            }
            return res.status(201).send();
        });
    });

If the destination file is incorrect or my permissions are wrong I get this error : /Users/Nicolas/Documents/Davidson/Adeo/Mobility/feedback-product/node_modules/ssh2-streams/lib/sftp.js:878 throw new Error('handle is not a Buffer');

Am I missing something, or is ssh2-streams not managing the error correctly ? (As far as I know you're not supposed to throw errors in async functions in NodeJs, only return them)