Syncano/syncano-js

No error on wrong API Key

Closed this issue · 0 comments

My code:

var CONFIG = {
  "syncano_account_key": "SYNCANO ACCOUNT KEY"
}

var Syncano = require('syncano');

function log(content) {
    console.log(content);
}

function pushToSyncano(videosList) {
    success = function(res) {
        log('Success saving data to Syncano: ' + JSON.stringify(res));
    };
    error = function(err) {
        log('Error saving data to Syncano: ' + JSON.stringify(err));
    };

    for (var i = 0; i < videosList.length; i++) {
        var video = videosList[i];
        account.instance('youtube').class('videos').dataobject().add(video).then(success).catch(error);
    }
}

var account = new Syncano({accountKey: CONFIG.syncano_account_key});

var video = {
            source_id: 20,
            url: 'https://youtube.com/watch?v=' + 'fake',
            title: 'title',
            description: 'description',
            published_at: '',
            other_permissions: 'read'
        };

pushToSyncano([video]);

Print to console is:

Success saving data to Syncano: {"detail":"No such API Key."}

Shouldn't that be handled in catch?

When I change my code to use callbacks:

callback = function(err,res) {
        log('Response: ' + JSON.stringify(res));
        log('Error: ' + JSON.stringify(err));
    }

    for (var i = 0; i < videosList.length; i++) {
        var video = videosList[i];
        account.instance('youtube').class('videos').dataobject().add(video, callback)

I get in console:

Response: {"detail":"No such API Key."}
Error: null

so it's also not caught as error by the library.