diff --git a/packages/health-check/src/checks/verbose.js b/packages/health-check/src/checks/verbose.js index e244a4dd..9c5ee9ee 100644 --- a/packages/health-check/src/checks/verbose.js +++ b/packages/health-check/src/checks/verbose.js @@ -2,7 +2,7 @@ const superagent = require("superagent"); const hash = require("object-hash"); const { detailedDiff } = require("deep-object-diff"); const { isEqual } = require("lodash"); -const { calculateElapsedTime, getResponseContent } = require("../utils"); +const { calculateElapsedTime, ensureValidJSON, getResponseContent } = require("../utils"); // audioExampleCheck returns the result of trying to download the skylink // for the Example audio file on siasky.net @@ -918,7 +918,7 @@ function skylinkVerification(done, { name, skylink, bodyHash, metadata }) { if (!isEqual(currentMetadata, metadata)) { entry.up = false; - info.metadata = detailedDiff(metadata, currentMetadata); + info.metadata = ensureValidJSON(detailedDiff(metadata, currentMetadata)); } if (Object.keys(info).length) entry.info = info; // add info only if it exists diff --git a/packages/health-check/src/utils.js b/packages/health-check/src/utils.js index 57be7a81..4af87d0b 100644 --- a/packages/health-check/src/utils.js +++ b/packages/health-check/src/utils.js @@ -29,8 +29,19 @@ function getResponseContent(response) { } } +/** + * Ensures that the object serializes to JSON properly + */ +function ensureValidJSON(object) { + const replacer = (key, value) => (value === undefined ? "--undefined--" : value); + const stringified = JSON.stringify(object, replacer); + + return JSON.parse(stringified); +} + module.exports = { calculateElapsedTime, getYesterdayISOString, getResponseContent, + ensureValidJSON, };