improve health checks

This commit is contained in:
Karol Wypchlo 2021-04-27 18:30:51 +02:00
parent b0641fc334
commit cedef4f1bb
5 changed files with 1401 additions and 4295 deletions

View File

@ -6,12 +6,12 @@
"dependencies": { "dependencies": {
"deep-object-diff": "^1.1.0", "deep-object-diff": "^1.1.0",
"express": "^4.17.1", "express": "^4.17.1",
"form-data": "^3.0.1",
"got": "^11.8.2",
"hasha": "^5.2.2",
"http-status-codes": "^2.1.2", "http-status-codes": "^2.1.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"lowdb": "^1.0.0", "lowdb": "^1.0.0",
"object-hash": "^2.1.1",
"superagent": "^6.0.0",
"tmp": "^0.2.1",
"yargs": "^16.2.0" "yargs": "^16.2.0"
}, },
"devDependencies": { "devDependencies": {

View File

@ -1,32 +1,33 @@
const fs = require("fs"); const got = require("got");
const superagent = require("superagent"); const FormData = require("form-data");
const tmp = require("tmp");
const { StatusCodes } = require("http-status-codes"); const { StatusCodes } = require("http-status-codes");
const { calculateElapsedTime, getResponseContent } = require("../utils"); const { calculateElapsedTime, getResponseContent } = require("../utils");
// uploadCheck returns the result of uploading a sample file // uploadCheck returns the result of uploading a sample file
async function uploadCheck(done) { async function uploadCheck(done) {
const time = process.hrtime(); const time = process.hrtime();
const file = tmp.fileSync(); const form = new FormData();
const data = Buffer.from(new Date()); // current date to ensure data uniqueness
fs.writeSync(file.fd, Buffer.from(new Date())); // write current date to temp file form.append("file", data, { filename: "time.txt", contentType: "text/plain" });
let statusCode, errorResponseContent;
superagent try {
.post(`${process.env.PORTAL_URL}/skynet/skyfile`) const response = await got.post(`${process.env.PORTAL_URL}/skynet/skyfile`, { body: form });
.attach("file", file.name, file.name)
.end((error, response) => {
file.removeCallback();
const statusCode = (response && response.statusCode) || (error && error.statusCode) || null; statusCode = response.statusCode;
} catch (error) {
statusCode = error?.response?.statusCode || error.statusCode || error.status;
errorResponseContent = getResponseContent(error?.response);
}
done({ done({
name: "upload_file", name: "upload_file",
up: statusCode === StatusCodes.OK, up: statusCode === StatusCodes.OK,
statusCode, statusCode,
errorResponseContent: getResponseContent(error?.response), errorResponseContent,
time: calculateElapsedTime(time), time: calculateElapsedTime(time),
}); });
});
} }
// downloadCheck returns the result of downloading the hard coded link // downloadCheck returns the result of downloading the hard coded link
@ -36,11 +37,12 @@ async function downloadCheck(done) {
let statusCode, errorResponseContent; let statusCode, errorResponseContent;
try { try {
const response = await superagent.get(`${process.env.PORTAL_URL}/${skylink}?nocache=true`); const response = await got(`${process.env.PORTAL_URL}/${skylink}?nocache=true`);
statusCode = response.statusCode; statusCode = response.statusCode;
} catch (error) { } catch (error) {
statusCode = error.statusCode || error.status; statusCode = error?.response?.statusCode || error.statusCode || error.status;
errorMessage = error.message;
errorResponseContent = getResponseContent(error.response); errorResponseContent = getResponseContent(error.response);
} }

View File

@ -1,5 +1,6 @@
const superagent = require("superagent"); const superagent = require("superagent");
const hash = require("object-hash"); const got = require("got");
const hasha = require("hasha");
const { detailedDiff } = require("deep-object-diff"); const { detailedDiff } = require("deep-object-diff");
const { isEqual } = require("lodash"); const { isEqual } = require("lodash");
const { calculateElapsedTime, ensureValidJSON, getResponseContent } = require("../utils"); const { calculateElapsedTime, ensureValidJSON, getResponseContent } = require("../utils");
@ -10,7 +11,7 @@ function audioExampleCheck(done) {
const linkInfo = { const linkInfo = {
name: "Audio Example", name: "Audio Example",
skylink: "_A2zt5SKoqwnnZU4cBF8uBycSKULXMyeg1c5ZISBr2Q3dA", skylink: "_A2zt5SKoqwnnZU4cBF8uBycSKULXMyeg1c5ZISBr2Q3dA",
bodyHash: "be335f5ad9bc357248f3d35c7e49df491afb6b12", bodyHash: "1bea1f570043f20149ae4cb4d30089d90897b15b",
headers: { headers: {
"skynet-skylink": "_A2zt5SKoqwnnZU4cBF8uBycSKULXMyeg1c5ZISBr2Q3dA", "skynet-skylink": "_A2zt5SKoqwnnZU4cBF8uBycSKULXMyeg1c5ZISBr2Q3dA",
"skynet-file-metadata": { filename: "feel-good.mp3" }, "skynet-file-metadata": { filename: "feel-good.mp3" },
@ -28,7 +29,7 @@ function covid19PaperCheck(done) {
const linkInfo = { const linkInfo = {
name: "Covid-19 Paper", name: "Covid-19 Paper",
skylink: "PAMZVmfutxWoG6Wnl5BRKuWLkDNZR42k_okRRvksJekA3A", skylink: "PAMZVmfutxWoG6Wnl5BRKuWLkDNZR42k_okRRvksJekA3A",
bodyHash: "81b9fb74829a96ceafa429840d1ef0ce44376ddd", bodyHash: "7ce20bfc4221503fd0bf909ad20c422eca125c7d",
headers: { headers: {
"skynet-skylink": "PAMZVmfutxWoG6Wnl5BRKuWLkDNZR42k_okRRvksJekA3A", "skynet-skylink": "PAMZVmfutxWoG6Wnl5BRKuWLkDNZR42k_okRRvksJekA3A",
"skynet-file-metadata": { "skynet-file-metadata": {
@ -55,7 +56,7 @@ function covid19CoroNopePaperCheck(done) {
const linkInfo = { const linkInfo = {
name: "Covid-19 CoroNope Paper", name: "Covid-19 CoroNope Paper",
skylink: "bACLKGmcmX4NCp47WwOOJf0lU666VLeT5HRWpWVtqZPjEA", skylink: "bACLKGmcmX4NCp47WwOOJf0lU666VLeT5HRWpWVtqZPjEA",
bodyHash: "901f6fd65ef595f70b6bfebbb2d05942351ef2b3", bodyHash: "0db705da1b1232f8344ed74fd38245d35a49a965",
headers: { headers: {
"skynet-skylink": "bACLKGmcmX4NCp47WwOOJf0lU666VLeT5HRWpWVtqZPjEA", "skynet-skylink": "bACLKGmcmX4NCp47WwOOJf0lU666VLeT5HRWpWVtqZPjEA",
"skynet-file-metadata": { filename: "coronope.pdf" }, "skynet-file-metadata": { filename: "coronope.pdf" },
@ -73,7 +74,7 @@ function dappExampleCheck(done) {
const linkInfo = { const linkInfo = {
name: "Dapp Example (UniSwap)", name: "Dapp Example (UniSwap)",
skylink: "EADWpKD0myqH2tZa6xtKebg6kNnwYnI94fl4R8UKgNrmOA", skylink: "EADWpKD0myqH2tZa6xtKebg6kNnwYnI94fl4R8UKgNrmOA",
bodyHash: "d6ad2506590bb45b5acc6a8a964a3da4d657354f", bodyHash: "7b74cbb5927e964db493b82cc1f8a532f1ff72f5",
headers: { headers: {
"skynet-skylink": "EADWpKD0myqH2tZa6xtKebg6kNnwYnI94fl4R8UKgNrmOA", "skynet-skylink": "EADWpKD0myqH2tZa6xtKebg6kNnwYnI94fl4R8UKgNrmOA",
"skynet-file-metadata": { "skynet-file-metadata": {
@ -624,7 +625,7 @@ function htmlExampleCheck(done) {
const linkInfo = { const linkInfo = {
name: "HTML Example", name: "HTML Example",
skylink: "PAL0w4SdA5rFCDGEutgpeQ50Om-YkBabtXVOJAkmedslKw", skylink: "PAL0w4SdA5rFCDGEutgpeQ50Om-YkBabtXVOJAkmedslKw",
bodyHash: "c932fd56f98b6db589e56be8018817f13bb29f72", bodyHash: "ecffcfbb74e017698cad30a91a74b9ba0b046413",
headers: { headers: {
"skynet-skylink": "PAL0w4SdA5rFCDGEutgpeQ50Om-YkBabtXVOJAkmedslKw", "skynet-skylink": "PAL0w4SdA5rFCDGEutgpeQ50Om-YkBabtXVOJAkmedslKw",
"skynet-file-metadata": { filename: "introduction â\x80\x93 Sia API Documentation.html" }, "skynet-file-metadata": { filename: "introduction â\x80\x93 Sia API Documentation.html" },
@ -642,7 +643,7 @@ function imageExampleCheck(done) {
const linkInfo = { const linkInfo = {
name: "Image Example", name: "Image Example",
skylink: "IADUs8d9CQjUO34LmdaaNPK_STuZo24rpKVfYW3wPPM2uQ", skylink: "IADUs8d9CQjUO34LmdaaNPK_STuZo24rpKVfYW3wPPM2uQ",
bodyHash: "313207978d0a88bf2b961f098804e9ab0f82837f", bodyHash: "e318667a9d53a45a9d010ac4e0d120ad064279ac",
headers: { headers: {
"skynet-skylink": "IADUs8d9CQjUO34LmdaaNPK_STuZo24rpKVfYW3wPPM2uQ", "skynet-skylink": "IADUs8d9CQjUO34LmdaaNPK_STuZo24rpKVfYW3wPPM2uQ",
"skynet-file-metadata": { filename: "sia-lm.png" }, "skynet-file-metadata": { filename: "sia-lm.png" },
@ -660,7 +661,7 @@ function jsonExampleCheck(done) {
const linkInfo = { const linkInfo = {
name: "JSON Example", name: "JSON Example",
skylink: "AAC0uO43g64ULpyrW0zO3bjEknSFbAhm8c-RFP21EQlmSQ", skylink: "AAC0uO43g64ULpyrW0zO3bjEknSFbAhm8c-RFP21EQlmSQ",
bodyHash: "198771c3d07d5c7302aadcc0697a7298e5e8ccc3", bodyHash: "b514603ce8acd937197712700e21259f18a857d6",
headers: { headers: {
"skynet-skylink": "AAC0uO43g64ULpyrW0zO3bjEknSFbAhm8c-RFP21EQlmSQ", "skynet-skylink": "AAC0uO43g64ULpyrW0zO3bjEknSFbAhm8c-RFP21EQlmSQ",
"skynet-file-metadata": { filename: "consensus.json" }, "skynet-file-metadata": { filename: "consensus.json" },
@ -678,7 +679,7 @@ function pdfExampleCheck(done) {
const linkInfo = { const linkInfo = {
name: "PDF Example", name: "PDF Example",
skylink: "XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg", skylink: "XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg",
bodyHash: "9bd8162e1575569a9041972f7f62d65887063dc3", bodyHash: "7e079f7afc9e5bc0c1be04543e22ac552a14a8da",
headers: { headers: {
"skynet-skylink": "XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg", "skynet-skylink": "XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg",
"skynet-file-metadata": { filename: "sia.pdf" }, "skynet-file-metadata": { filename: "sia.pdf" },
@ -739,7 +740,7 @@ function skyBayCheck(done) {
const linkInfo = { const linkInfo = {
name: "SkyBay", name: "SkyBay",
skylink: "EABkMjXzxJRpPz0eO0Or5fy2eo-rz3prdigGwRlyNd9mwA/", skylink: "EABkMjXzxJRpPz0eO0Or5fy2eo-rz3prdigGwRlyNd9mwA/",
bodyHash: "25d63937c9734fb08d2749c6517d1b3de8ecb856", bodyHash: "dfc0b1d3d1113254d7545d19f6118855ed9c778b",
headers: { headers: {
"skynet-skylink": "EABkMjXzxJRpPz0eO0Or5fy2eo-rz3prdigGwRlyNd9mwA", "skynet-skylink": "EABkMjXzxJRpPz0eO0Or5fy2eo-rz3prdigGwRlyNd9mwA",
"skynet-file-metadata": { "skynet-file-metadata": {
@ -760,7 +761,7 @@ function skyBayRedirectCheck(done) {
const linkInfo = { const linkInfo = {
name: "SkyBay Redirect", name: "SkyBay Redirect",
skylink: "EABkMjXzxJRpPz0eO0Or5fy2eo-rz3prdigGwRlyNd9mwA", skylink: "EABkMjXzxJRpPz0eO0Or5fy2eo-rz3prdigGwRlyNd9mwA",
bodyHash: "25d63937c9734fb08d2749c6517d1b3de8ecb856", bodyHash: "dfc0b1d3d1113254d7545d19f6118855ed9c778b",
headers: { headers: {
"skynet-skylink": "EABkMjXzxJRpPz0eO0Or5fy2eo-rz3prdigGwRlyNd9mwA", "skynet-skylink": "EABkMjXzxJRpPz0eO0Or5fy2eo-rz3prdigGwRlyNd9mwA",
"skynet-file-metadata": { "skynet-file-metadata": {
@ -780,7 +781,7 @@ function skyBinCheck(done) {
const linkInfo = { const linkInfo = {
name: "SkyBin", name: "SkyBin",
skylink: "CAAVU14pB9GRIqCrejD7rlS27HltGGiiCLICzmrBV0wVtA/", skylink: "CAAVU14pB9GRIqCrejD7rlS27HltGGiiCLICzmrBV0wVtA/",
bodyHash: "767ec67c417e11b97c5db7dad9ea3b6b27cb0d39", bodyHash: "858ff733c4cb06a80060b8a62cf303fd5a051651",
headers: { headers: {
"skynet-skylink": "CAAVU14pB9GRIqCrejD7rlS27HltGGiiCLICzmrBV0wVtA", "skynet-skylink": "CAAVU14pB9GRIqCrejD7rlS27HltGGiiCLICzmrBV0wVtA",
"skynet-file-metadata": { filename: "skybin.html" }, "skynet-file-metadata": { filename: "skybin.html" },
@ -798,7 +799,7 @@ function skyBinRedirectCheck(done) {
const linkInfo = { const linkInfo = {
name: "SkyBin Redirect", name: "SkyBin Redirect",
skylink: "CAAVU14pB9GRIqCrejD7rlS27HltGGiiCLICzmrBV0wVtA", skylink: "CAAVU14pB9GRIqCrejD7rlS27HltGGiiCLICzmrBV0wVtA",
bodyHash: "767ec67c417e11b97c5db7dad9ea3b6b27cb0d39", bodyHash: "858ff733c4cb06a80060b8a62cf303fd5a051651",
headers: { headers: {
"skynet-skylink": "CAAVU14pB9GRIqCrejD7rlS27HltGGiiCLICzmrBV0wVtA", "skynet-skylink": "CAAVU14pB9GRIqCrejD7rlS27HltGGiiCLICzmrBV0wVtA",
"skynet-file-metadata": { filename: "skybin.html" }, "skynet-file-metadata": { filename: "skybin.html" },
@ -874,9 +875,9 @@ function skyGalleryRedirectCheck(done) {
// for the uncensored library skylink // for the uncensored library skylink
function uncensoredLibraryCheck(done) { function uncensoredLibraryCheck(done) {
const linkInfo = { const linkInfo = {
name: "The Uncensored Library V2", name: "Unzip The Uncensored Library Map",
skylink: "AAC5glnZyNJ4Ieb4MhnYJGtID6qdMqEjl0or5EvEMt7bWQ", skylink: "AAC5glnZyNJ4Ieb4MhnYJGtID6qdMqEjl0or5EvEMt7bWQ",
bodyHash: "60da6cb958699c5acd7f2a2911656ff32fca89a7", bodyHash: "cd0377661eefd656c8b46c497aa03112393ba893",
headers: { headers: {
"skynet-skylink": "AAC5glnZyNJ4Ieb4MhnYJGtID6qdMqEjl0or5EvEMt7bWQ", "skynet-skylink": "AAC5glnZyNJ4Ieb4MhnYJGtID6qdMqEjl0or5EvEMt7bWQ",
"skynet-file-metadata": { "skynet-file-metadata": {
@ -901,7 +902,7 @@ function uncensoredLibraryPressReleaseCheck(done) {
const linkInfo = { const linkInfo = {
name: "The Uncensored Library - Press Release", name: "The Uncensored Library - Press Release",
skylink: "AABHwuml_EhvyY8Gm7j1E2xGwodUNAJgX0A6-Cd22p9kNA", skylink: "AABHwuml_EhvyY8Gm7j1E2xGwodUNAJgX0A6-Cd22p9kNA",
bodyHash: "323217f643c3e3f1fe7532e72ac01bb0748c97be", bodyHash: "da39a3ee5e6b4b0d3255bfef95601890afd80709",
headers: { headers: {
"skynet-skylink": "AABHwuml_EhvyY8Gm7j1E2xGwodUNAJgX0A6-Cd22p9kNA", "skynet-skylink": "AABHwuml_EhvyY8Gm7j1E2xGwodUNAJgX0A6-Cd22p9kNA",
"skynet-file-metadata": { "skynet-file-metadata": {
@ -927,7 +928,7 @@ function uncensoredLibraryV2Check(done) {
const linkInfo = { const linkInfo = {
name: "The Uncensored Library V2", name: "The Uncensored Library V2",
skylink: "AAAs-JOsRGWgABYIo7AwTDqSX79-BxQKjDj0wiRGoRPFnw", skylink: "AAAs-JOsRGWgABYIo7AwTDqSX79-BxQKjDj0wiRGoRPFnw",
bodyHash: "1c6a885c060af8325eee82a11e9d64a13b228015", bodyHash: "f2a802c2b7482825613a08853538203a53c96bd1",
headers: { headers: {
"skynet-skylink": "AAAs-JOsRGWgABYIo7AwTDqSX79-BxQKjDj0wiRGoRPFnw", "skynet-skylink": "AAAs-JOsRGWgABYIo7AwTDqSX79-BxQKjDj0wiRGoRPFnw",
"skynet-file-metadata": { "skynet-file-metadata": {
@ -952,7 +953,7 @@ function bitcoinWhitepaper(done) {
skylinkVerification(done, { skylinkVerification(done, {
name: "Bitcoin Whitepaper", name: "Bitcoin Whitepaper",
skylink: "3ACpC9Umme41zlWUgMQh1fw0sNwgWwyfDDhRQ9Sppz9hjQ", skylink: "3ACpC9Umme41zlWUgMQh1fw0sNwgWwyfDDhRQ9Sppz9hjQ",
bodyHash: "5d1fd2c37c1a3409cfc41861f4206472559670f3", bodyHash: "8de2fdb04edce612738eb51e14ecc426381f8ed8",
headers: { headers: {
"skynet-skylink": "3ACpC9Umme41zlWUgMQh1fw0sNwgWwyfDDhRQ9Sppz9hjQ", "skynet-skylink": "3ACpC9Umme41zlWUgMQh1fw0sNwgWwyfDDhRQ9Sppz9hjQ",
"content-disposition": 'inline; filename="bitcoin.pdf"', "content-disposition": 'inline; filename="bitcoin.pdf"',
@ -1039,7 +1040,7 @@ function uniswapHNSResolverCheck(done) {
const linkInfo = { const linkInfo = {
name: "Uniswap HNS Resolver", name: "Uniswap HNS Resolver",
skylink: "hnsres/uniswap-dex/", skylink: "hnsres/uniswap-dex/",
bodyHash: "44a3f0f56861ae841a6cb19cb0b3edf98ad610f8", bodyHash: "3634496800c254b93f9dcbca2aeb53e644f706c0",
}; };
skylinkVerification(done, linkInfo); skylinkVerification(done, linkInfo);
@ -1052,7 +1053,7 @@ function uniswapHNSResolverRedirectCheck(done) {
const linkInfo = { const linkInfo = {
name: "Uniswap HNS Resolver Redirect", name: "Uniswap HNS Resolver Redirect",
skylink: "hnsres/uniswap-dex", skylink: "hnsres/uniswap-dex",
bodyHash: "44a3f0f56861ae841a6cb19cb0b3edf98ad610f8", bodyHash: "3634496800c254b93f9dcbca2aeb53e644f706c0",
}; };
skylinkVerification(done, linkInfo); skylinkVerification(done, linkInfo);
@ -1063,7 +1064,7 @@ function fileEndpointCheck(done) {
const linkInfo = { const linkInfo = {
name: "File endpoint check", name: "File endpoint check",
skylink: "file/XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg", skylink: "file/XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg",
bodyHash: "9bd8162e1575569a9041972f7f62d65887063dc3", bodyHash: "7e079f7afc9e5bc0c1be04543e22ac552a14a8da",
headers: { headers: {
"skynet-skylink": "XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg", "skynet-skylink": "XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg",
"skynet-file-metadata": { filename: "sia.pdf" }, "skynet-file-metadata": { filename: "sia.pdf" },
@ -1086,7 +1087,7 @@ function hnsEndpointDirectoryRedirect(done) {
}, },
}; };
skylinkVerification(done, expected, { redirects: 0 }); skylinkVerification(done, expected, { followRedirect: false });
} }
function parseHeaderString(header) { function parseHeaderString(header) {
@ -1098,43 +1099,38 @@ function parseHeaderString(header) {
} }
// skylinkVerification verifies a skylink against provided information. // skylinkVerification verifies a skylink against provided information.
function skylinkVerification(done, { name, skylink, bodyHash, headers, statusCode }, { redirects, method } = {}) { async function skylinkVerification(done, expected, { followRedirect = true, method = "get" } = {}) {
const time = process.hrtime(); const time = process.hrtime();
// Create the query for the skylink // Create the query for the skylink
const query = `${process.env.PORTAL_URL}/${skylink}`; const query = `${process.env.PORTAL_URL}/${expected.skylink}`;
// Get the Skylink try {
superagent[method || "get"](query) const response = await got[method](query, { followRedirect, headers: { cookie: "nocache=true" } });
.set("cookie", "nocache=true") // const [response, buffer] = await Promise.all([promise, promise.buffer()]);
.redirects(redirects) const entry = { name: expected.name, up: true, statusCode: response.statusCode, time: calculateElapsedTime(time) };
.ok((res) => (redirects === undefined ? res.ok : res.status < 400))
.responseType("blob")
.then(
(response) => {
const entry = { name, up: true, statusCode: response.statusCode, time: calculateElapsedTime(time) };
const info = {}; const info = {};
if (statusCode && statusCode !== response.statusCode) { if (expected.statusCode && expected.statusCode !== response.statusCode) {
entry.up = false; entry.up = false;
info.statusCode = { expected: statusCode, current: response.statusCode }; info.statusCode = { expected: expected.statusCode, current: response.statusCode };
} }
// Check if the response body is valid by checking against the known hash // Check if the response body is valid by checking against the known hash
if (bodyHash) { if (expected.bodyHash) {
const currentBodyHash = hash(response.body); const currentBodyHash = hasha(response.rawBody, { algorithm: "sha1" });
if (currentBodyHash !== bodyHash) { if (currentBodyHash !== expected.bodyHash) {
console.log(expected.name, currentBodyHash);
entry.up = false; entry.up = false;
info.bodyHash = { expected: bodyHash, current: currentBodyHash }; info.bodyHash = { expected: expected.bodyHash, current: currentBodyHash };
} }
} }
if (headers) { if (expected.headers) {
Object.entries(headers).forEach(([headerName, expectedHeader]) => { Object.entries(expected.headers).forEach(([headerName, expectedHeader]) => {
const currentHeader = parseHeaderString(response.header[headerName]); const currentHeader = parseHeaderString(response.headers[headerName]);
if (!isEqual(currentHeader, expectedHeader)) { if (!isEqual(currentHeader, expectedHeader)) {
entry.up = false; entry.up = false;
info.headers = info.headers ?? {}; info.headers = info.headers ?? {};
if (typeof currentHeader === "object") { if (typeof currentHeader === "object") {
info.headers[headerName] = ensureValidJSON(detailedDiff(expectedHeader, currentHeader)); info.headers[headerName] = ensureValidJSON(detailedDiff(expectedHeader, currentHeader));
@ -1148,19 +1144,16 @@ function skylinkVerification(done, { name, skylink, bodyHash, headers, statusCod
if (Object.keys(info).length) entry.info = info; // add info only if it exists if (Object.keys(info).length) entry.info = info; // add info only if it exists
done(entry); // Return the entry information done(entry); // Return the entry information
}, } catch (error) {
(error) => {
console.log(error);
done({ done({
name, name: expected.name,
up: false, up: false,
statusCode: error.statusCode || error.status, statusCode: error?.response?.statusCode || error.statusCode || error.status,
errorMessage: error.message,
errorResponseContent: getResponseContent(error.response), errorResponseContent: getResponseContent(error.response),
time: calculateElapsedTime(time), time: calculateElapsedTime(time),
}); });
} }
);
} }
module.exports = [ module.exports = [

View File

@ -23,9 +23,9 @@ function getYesterdayISOString() {
*/ */
function getResponseContent(response) { function getResponseContent(response) {
try { try {
return JSON.parse(response?.text); return JSON.parse(response?.body || response?.text);
} catch { } catch {
return response?.text; return response?.body || response?.text;
} }
} }

5499
yarn.lock

File diff suppressed because it is too large Load Diff