[MediaWiki-commits] [Gerrit] mediawiki...mobileapps[master]: Show MW API requests when debug is true
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/402129 ) Change subject: Show MW API requests when debug is true .. Show MW API requests when debug is true To make it easier to debug backend requests I think it is useful to see the full query string made to the MW API. There can be tons of query parameters, and it's quite tedious to compile them manually. To turn this on just set the DEBUG constant in api-util.js to true and look for "outgoing request" messages in the log file. Change-Id: Ibd8196b98d90e0431650b4fabc56ef006af16d10 --- M lib/api-util.js 1 file changed, 11 insertions(+), 1 deletion(-) Approvals: jenkins-bot: Verified Mholloway: Looks good to me, approved diff --git a/lib/api-util.js b/lib/api-util.js index efb4686..3d053fc 100644 --- a/lib/api-util.js +++ b/lib/api-util.js @@ -2,13 +2,19 @@ const BBPromise = require('bluebird'); const preq = require('preq'); +const querystring = require('querystring'); const sUtil = require('./util'); const Template = require('swagger-router').Template; const HTTPError = sUtil.HTTPError; const MAX_BATCH_SIZE = 50; +const DEBUG = false; - +function prettyMwApiReq(request) { +// formatting it as GET request even though we use POST requests for MW API, +// just because GETs are easier to run from commandline or see it in a browser +return `${request.uri}?${querystring.stringify(request.body)}`; +} /** * Calls the MW API with the supplied query as its body * @param {!Object} app the application object @@ -29,6 +35,10 @@ } }); +if (DEBUG) { +app.logger.log(`trace/mwApiGet`, { msg: 'outgoing request', to: prettyMwApiReq(request) }); +} + return preq(request).then((response) => { if (response.status < 200 || response.status > 399) { // there was an error when calling the upstream service, propagate that -- To view, visit https://gerrit.wikimedia.org/r/402129 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ibd8196b98d90e0431650b4fabc56ef006af16d10 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/mobileapps Gerrit-Branch: master Gerrit-Owner: BearNDGerrit-Reviewer: Fjalapeno Gerrit-Reviewer: Jdlrobson Gerrit-Reviewer: Mholloway Gerrit-Reviewer: Mhurd Gerrit-Reviewer: Ppchelko Gerrit-Reviewer: jenkins-bot <> ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki...mobileapps[master]: Show MW API requests when debug is true
BearND has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/402129 ) Change subject: Show MW API requests when debug is true .. Show MW API requests when debug is true To make it easier to debug backend requests I think it is useful to see the full query string made to the MW API. There can be tons of query parameters, and it's quite tedious to compile them manually. To turn this on just set the DEBUG constant in api-util.js to true and look for "outgoing request" messages in the log file. Change-Id: Ibd8196b98d90e0431650b4fabc56ef006af16d10 --- M lib/api-util.js 1 file changed, 11 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps refs/changes/29/402129/1 diff --git a/lib/api-util.js b/lib/api-util.js index efb4686..3d053fc 100644 --- a/lib/api-util.js +++ b/lib/api-util.js @@ -2,13 +2,19 @@ const BBPromise = require('bluebird'); const preq = require('preq'); +const querystring = require('querystring'); const sUtil = require('./util'); const Template = require('swagger-router').Template; const HTTPError = sUtil.HTTPError; const MAX_BATCH_SIZE = 50; +const DEBUG = false; - +function prettyMwApiReq(request) { +// formatting it as GET request even though we use POST requests for MW API, +// just because GETs are easier to run from commandline or see it in a browser +return `${request.uri}?${querystring.stringify(request.body)}`; +} /** * Calls the MW API with the supplied query as its body * @param {!Object} app the application object @@ -29,6 +35,10 @@ } }); +if (DEBUG) { +app.logger.log(`trace/mwApiGet`, { msg: 'outgoing request', to: prettyMwApiReq(request) }); +} + return preq(request).then((response) => { if (response.status < 200 || response.status > 399) { // there was an error when calling the upstream service, propagate that -- To view, visit https://gerrit.wikimedia.org/r/402129 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibd8196b98d90e0431650b4fabc56ef006af16d10 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/mobileapps Gerrit-Branch: master Gerrit-Owner: BearND___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits