Skip to content

Commit

Permalink
Issue #13: less "strict" error checking in api.js + SMW example
Browse files Browse the repository at this point in the history
  • Loading branch information
macbre committed Feb 6, 2013
1 parent af6cd6f commit f12f420
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions examples/smw.js
@@ -0,0 +1,19 @@
/**
* Example script of Semantic MediaWiki integration
*
* @see http://semantic-mediawiki.org/wiki/Ask_API
*/

var bot = require('../lib/bot').bot,
client = new bot({
server: 'semantic-mediawiki.org',
path: '/w'
}),
params = {
action: 'ask',
query: '[[Modification date::+]]|?Modification date|sort=Modification date|order=desc'
};

client.api.call(params, function(info, next, data) {
console.log(data && data.query && data.query.results);
});
4 changes: 2 additions & 2 deletions lib/api.js
Expand Up @@ -175,7 +175,7 @@
throw 'Error parsing JSON response: ' + res.body;
}

if (info) {
if (data && !data.error) {
if (typeof callback === 'function') {
callback && callback(info, next, data);
}
Expand All @@ -185,7 +185,7 @@
data: data
});
}
else if (data.error) {
else {
throw 'Error returned by API: ' + data.error.info;
}
});
Expand Down

0 comments on commit f12f420

Please sign in to comment.