Skip to content

Commit

Permalink
Replace console.error with Reliability Kit logger
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanmanning committed Jan 17, 2024
1 parent f1bbb6f commit 8885436
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/checks/json.check.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const status = require('./status');
const Check = require('./check');
const fetch = require('node-fetch');
const fetchres = require('fetchres');
const logger = require('@dotcom-reliability-kit/logger');

class JsonCheck extends Check{

Expand All @@ -24,8 +25,11 @@ class JsonCheck extends Check{

let result = this.callback(json);
this.status = result ? status.PASSED : status.FAILED;
} catch(err) {
console.error('Failed to get JSON', err);
} catch(error) {
logger.error({
event: 'JSON_CHECK_ERROR',
message: `Failed to fetch JSON from ${this.url}`
}, error);
this.status = status.FAILED;
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/checks/responseCompare.check.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const status = require('./status');
const Check = require('./check');
const fetch = require('node-fetch');
const logger = require('@dotcom-reliability-kit/logger');

function allEqual(responses){
for(let i = 1, l = responses.length; i < l; i++){
Expand Down Expand Up @@ -49,8 +50,11 @@ class ResponseCompareCheck extends Check {
if(this.comparison === ResponseCompareCheck.comparisons.EQUAL){
this.status = allEqual(responses) ? status.PASSED : status.FAILED;
}
} catch(err) {
console.error('Response was not OK', err);
} catch(error) {
logger.error({
event: 'RESPONSE_COMPARE_CHECK_ERROR',
message: 'Response was not OK'
}, error);
this.status = status.FAILED;
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/checks/string.check.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const status = require('./status');
const Check = require('./check');
const fetch = require('node-fetch');
const fetchres = require('fetchres');
const logger = require('@dotcom-reliability-kit/logger');

class StringCheck extends Check {

Expand All @@ -25,8 +26,11 @@ class StringCheck extends Check {
try {
const body = await fetch(this.url, this.fetchOptions).then(fetchres.text);
this.status = body === this.expected ? status.PASSED : status.FAILED;
} catch(err) {
console.error('Response was not OK', err);
} catch(error) {
logger.error({
event: 'STRING_CHECK_ERROR',
message: 'Response was not OK'
}, error);
this.status = status.FAILED;
}
}
Expand Down

0 comments on commit 8885436

Please sign in to comment.