mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
* feature: Make all errors in console.error be including an error for that stack tract * feature: Make all errors in console.error be including an error for that stack tract * fix: Add the tinisubreaper for the subreapers to know they are not the reaper * fix: overlay always destroyed * chore: Move the style of destroy to just private
37 lines
972 B
TypeScript
37 lines
972 B
TypeScript
import { Effects } from "../../types"
|
|
import { asError } from "../../util/asError"
|
|
import { HealthCheckResult } from "./HealthCheckResult"
|
|
import { timeoutPromise } from "./index"
|
|
import "isomorphic-fetch"
|
|
|
|
/**
|
|
* This is a helper function to check if a web url is reachable.
|
|
* @param url
|
|
* @param createSuccess
|
|
* @returns
|
|
*/
|
|
export const checkWebUrl = async (
|
|
effects: Effects,
|
|
url: string,
|
|
{
|
|
timeout = 1000,
|
|
successMessage = `Reached ${url}`,
|
|
errorMessage = `Error while fetching URL: ${url}`,
|
|
} = {},
|
|
): Promise<HealthCheckResult> => {
|
|
return Promise.race([fetch(url), timeoutPromise(timeout)])
|
|
.then(
|
|
(x) =>
|
|
({
|
|
result: "success",
|
|
message: successMessage,
|
|
}) as const,
|
|
)
|
|
.catch((e) => {
|
|
console.warn(`Error while fetching URL: ${url}`)
|
|
console.error(JSON.stringify(e))
|
|
console.error(asError(e))
|
|
return { result: "failure" as const, message: errorMessage }
|
|
})
|
|
}
|