diff --git a/test/apiTests.js b/test/apiTests.js index c42e150..5ea1780 100644 --- a/test/apiTests.js +++ b/test/apiTests.js @@ -61,6 +61,7 @@ describe('API', () => { expect(log.error).to.be.called; expect(500).to.equal(spy.getCall(0).args[1].thirdPartyErrorCode); + expect("Unknown WPT issue").to.equal(spy.getCall(0).args[1].thirdPartyErrorBody); log.error.restore(); }); @@ -85,7 +86,7 @@ describe('API', () => { expect(log.warn).to.be.called; expect(log.error).to.not.be.called; expect(400).to.equal(spy.getCall(0).args[1].thirdPartyErrorCode); - expect("unknown issue").to.equal(spy.getCall(0).args[1].responseBody); + expect("unknown issue").to.equal(spy.getCall(0).args[1].thirdPartyErrorBody); log.error.restore(); log.warn.restore(); diff --git a/util/strings.js b/util/strings.js new file mode 100644 index 0000000..ec330b2 --- /dev/null +++ b/util/strings.js @@ -0,0 +1,6 @@ +const truncateString = (str, lim) => + str.length > lim ? str.slice(0, lim > 3 ? lim - 3 : lim) + '...' : str; + +module.exports = { + truncateString +} \ No newline at end of file diff --git a/wtp/apiCaller.js b/wtp/apiCaller.js index f03f894..33d9c8c 100644 --- a/wtp/apiCaller.js +++ b/wtp/apiCaller.js @@ -12,6 +12,7 @@ const logger = require('../logger'); const log = logger.logger; const resultParser = require('./wtpResultsParser'); const cloudinaryCaller = require('../cloudinary/apiCaller'); +const {truncateString} = require('../util/strings'); const RESULTS_URL = 'https://www.webpagetest.org/jsonResult.php'; const RUN_TEST_URL = 'http://www.webpagetest.org/runtest.php'; const GET_TEST_STATUS = 'http://www.webpagetest.org/testStatus.php'; @@ -80,12 +81,13 @@ const runWtpTest = async (url, mobile, cb) => { throwHttpErrors: false }; let response; - let rollBarMsg = {testId: "", analyzedUrl: url, thirdPartyErrorCode: "", file: path.basename((__filename))}; + let rollBarMsg = {testId: "", analyzedUrl: url, thirdPartyErrorCode: "", thirdPartyErrorMsg: "", file: path.basename((__filename))}; try { response = await got(options); const {statusCode, body} = response; if (statusCode !== 200) { rollBarMsg.thirdPartyErrorCode = response.statusCode; + rollBarMsg.thirdPartyErrorBody = body && truncateString(body, 1000) || ""; cb({status: 'error', message: 'WTP returned bad status with url ' + url, error: response.statusMessage, logLevel: logger.LOG_LEVEL_ERROR}, null, response, rollBarMsg); return; } diff --git a/wtp/wtpResultsParser.js b/wtp/wtpResultsParser.js index 9dcdd40..8630ab2 100644 --- a/wtp/wtpResultsParser.js +++ b/wtp/wtpResultsParser.js @@ -98,7 +98,7 @@ const parseTestResults = (testJson) => { const parseTestResponse = (body, rollBarMsg) => { if (body.statusText !== 'Ok') { rollBarMsg.thirdPartyErrorCode = body?.statusCode; - rollBarMsg.responseBody = body.statusText; + rollBarMsg.thirdPartyErrorBody = body.statusText; logger.warn('WPT returned an error', rollBarMsg); return {status: 'error', message: 'wpt_failure'} }