watson-developer-cloud / node-sdk

:comet: Node.js library to access IBM Watson services.
https://www.npmjs.com/package/ibm-watson
Apache License 2.0
1.48k stars 670 forks source link

[visual-recognition] Invalid API key message returned in results argument, not error argument #264

Closed nfriedly closed 8 years ago

nfriedly commented 8 years ago

When the visual recognition API is called with an invalid API key, an error is returned:

{ status: 'ERROR', statusInfo: 'invalid-api-key' }

However, this should be in the error argument, not the results argument for the callback function:

var path = require('path');
var fs = require('fs');
var watson = require('watson-developer-cloud');

var visualRecognition = watson.visual_recognition({
  api_key: 'bogus',
  version: 'v3',
  version_date: '2016-05-20'
});

visualRecognition.classify({
  images_file: fs.createReadStream(path.join(__dirname, '../../', 'public/images/bundles/dogs/test/1.jpg'))
}, function(err, res) {
  // expected: err should contain the error message, res should be null
  // actual: err is null and res contains the error message
  console.log(err, res);
});
abhibisht89 commented 7 years ago

also getting the same issue

nfriedly commented 7 years ago

@abhibisht89 what version of the Node.js SDK are you on? The fix for this was released over a year ago, and a test was added to prevent regressions. Please update to the latest version of the SDK (npm install watson-developer-cloud@latest --save) and then either confirm that it's working or open a new ticket with more details if you're still seeing an error.

Also, note that the bug here was that when you supply an invalid API key, it provides the error response in the data argument rather than in the error argument. However, an error is expected if you supply an invalid API key. If you are seeing this message in the error argument, then it is working as expected and you simply need to get a valid API key.