Skip to content

Commit 9fa85b0

Browse files
fix: not all WPT API errors logged (DELO-4614) (#77)
* fix: no WPT API errors logged (DELO-4614) * fix: use the same field for error details for the consistency sake * test
1 parent c5caf7b commit 9fa85b0

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

test/apiTests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ describe('API', () => {
6161

6262
expect(log.error).to.be.called;
6363
expect(500).to.equal(spy.getCall(0).args[1].thirdPartyErrorCode);
64+
expect("Unknown WPT issue").to.equal(spy.getCall(0).args[1].thirdPartyErrorBody);
6465

6566
log.error.restore();
6667
});
@@ -85,7 +86,7 @@ describe('API', () => {
8586
expect(log.warn).to.be.called;
8687
expect(log.error).to.not.be.called;
8788
expect(400).to.equal(spy.getCall(0).args[1].thirdPartyErrorCode);
88-
expect("unknown issue").to.equal(spy.getCall(0).args[1].responseBody);
89+
expect("unknown issue").to.equal(spy.getCall(0).args[1].thirdPartyErrorBody);
8990

9091
log.error.restore();
9192
log.warn.restore();

util/strings.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const truncateString = (str, lim) =>
2+
str.length > lim ? str.slice(0, lim > 3 ? lim - 3 : lim) + '...' : str;
3+
4+
module.exports = {
5+
truncateString
6+
}

wtp/apiCaller.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const logger = require('../logger');
1212
const log = logger.logger;
1313
const resultParser = require('./wtpResultsParser');
1414
const cloudinaryCaller = require('../cloudinary/apiCaller');
15+
const {truncateString} = require('../util/strings');
1516
const RESULTS_URL = 'https://www.webpagetest.org/jsonResult.php';
1617
const RUN_TEST_URL = 'http://www.webpagetest.org/runtest.php';
1718
const GET_TEST_STATUS = 'http://www.webpagetest.org/testStatus.php';
@@ -80,12 +81,13 @@ const runWtpTest = async (url, mobile, cb) => {
8081
throwHttpErrors: false
8182
};
8283
let response;
83-
let rollBarMsg = {testId: "", analyzedUrl: url, thirdPartyErrorCode: "", file: path.basename((__filename))};
84+
let rollBarMsg = {testId: "", analyzedUrl: url, thirdPartyErrorCode: "", thirdPartyErrorMsg: "", file: path.basename((__filename))};
8485
try {
8586
response = await got(options);
8687
const {statusCode, body} = response;
8788
if (statusCode !== 200) {
8889
rollBarMsg.thirdPartyErrorCode = response.statusCode;
90+
rollBarMsg.thirdPartyErrorBody = body && truncateString(body, 1000) || "";
8991
cb({status: 'error', message: 'WTP returned bad status with url ' + url, error: response.statusMessage, logLevel: logger.LOG_LEVEL_ERROR}, null, response, rollBarMsg);
9092
return;
9193
}

wtp/wtpResultsParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const parseTestResults = (testJson) => {
9898
const parseTestResponse = (body, rollBarMsg) => {
9999
if (body.statusText !== 'Ok') {
100100
rollBarMsg.thirdPartyErrorCode = body?.statusCode;
101-
rollBarMsg.responseBody = body.statusText;
101+
rollBarMsg.thirdPartyErrorBody = body.statusText;
102102
logger.warn('WPT returned an error', rollBarMsg);
103103
return {status: 'error', message: 'wpt_failure'}
104104
}

0 commit comments

Comments
 (0)