Yurik has uploaded a new change for review. https://gerrit.wikimedia.org/r/311410
Change subject: Fixed wikiraw: protocol bug ...................................................................... Fixed wikiraw: protocol bug Bug: T146010 Change-Id: I5c08e9fddbe62038eac00bd87b618efda6c05336 --- M lib/graph2.compiled.js 1 file changed, 26 insertions(+), 17 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Graph refs/changes/10/311410/1 diff --git a/lib/graph2.compiled.js b/lib/graph2.compiled.js index 43700d7..b0e6c74 100644 --- a/lib/graph2.compiled.js +++ b/lib/graph2.compiled.js @@ -506,29 +506,37 @@ * Performs post-processing of the data requested by the graph's spec */ VegaWrapper.prototype.dataParser = function dataParser(error, data, opt, callback) { - if (error) { - callback(error); - return; + if (!error) { + try { + data = this.parseDataOrThrow(data, opt); + } catch (e) { + error = e; + } } + if (error) data = undefined; + callback(error, data); +}; + +/** + * Performs post-processing of the data requested by the graph's spec, and throw on error + */ +VegaWrapper.prototype.parseDataOrThrow = function parseDataOrThrow(data, opt) { switch (opt.graphProtocol) { case 'wikiapi:': case 'wikiraw:': // This was an API call - check for errors data = JSON.parse(data); if (data.error) { - error = new Error('API error: ' + JSON.stringify(data.error)); - data = undefined; - } else { - if (data.warnings) { - this.logger('API warnings: ' + JSON.stringify(data.warnings)); - } - if (opt.graphProtocol === 'wikiraw') { - try { - data = data.query.pages[0].revisions[0].content; - } catch (e) { - data = undefined; - error = new Error('Page content not available ' + opt.url); - } + throw new Error('API error: ' + JSON.stringify(data.error)); + } + if (data.warnings) { + this.logger('API warnings: ' + JSON.stringify(data.warnings)); + } + if (opt.graphProtocol === 'wikiraw:') { + try { + data = data.query.pages[0].revisions[0].content; + } catch (e) { + throw new Error('Page content not available ' + opt.url); } } break; @@ -549,7 +557,8 @@ }); break; } - callback(error, data); + + return data; }; /** -- To view, visit https://gerrit.wikimedia.org/r/311410 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5c08e9fddbe62038eac00bd87b618efda6c05336 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Graph Gerrit-Branch: wmf/1.28.0-wmf.18 Gerrit-Owner: Yurik <yu...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits