mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-02 13:33:40 +01:00
Add try catch for ping
This commit is contained in:
parent
cead87dcd0
commit
f1a33f10ed
@ -15,21 +15,28 @@ export default async function handler(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let startTime = performance.now();
|
try {
|
||||||
let [status] = await httpProxy(pingURL, {
|
let startTime = performance.now();
|
||||||
method: "HEAD"
|
let [status] = await httpProxy(pingURL, {
|
||||||
});
|
method: "HEAD"
|
||||||
let endTime = performance.now();
|
});
|
||||||
|
let endTime = performance.now();
|
||||||
|
|
||||||
if (status > 403) {
|
if (status > 403) {
|
||||||
// try one more time as a GET in case HEAD is rejected for whatever reason
|
// try one more time as a GET in case HEAD is rejected for whatever reason
|
||||||
startTime = performance.now();
|
startTime = performance.now();
|
||||||
[status] = await httpProxy(pingURL);
|
[status] = await httpProxy(pingURL);
|
||||||
endTime = performance.now();
|
endTime = performance.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
status,
|
||||||
|
latency: endTime - startTime
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
logger.debug("Error attempting ping: %s", JSON.stringify(e));
|
||||||
|
return res.status(400).send({
|
||||||
|
error: 'Error attempting ping, see logs.',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(200).json({
|
|
||||||
status,
|
|
||||||
latency: endTime - startTime
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user