Merge pull request #10 from Start9Labs/Blu-J-patch-1

Update healthUtil.ts
This commit is contained in:
Lucy C
2022-11-15 12:09:40 -05:00
committed by GitHub

View File

@@ -1,12 +1,12 @@
import { Effects, ResultType } from "./types.ts";
import { error, errorCode, ok } from "./util.ts";
export const checkWebUrl: (
url: string,
) => (effects: Effects, duration: number) => Promise<ResultType<null | void>> =
(url) => {
return async (effects, duration) => {
await guardDurationAboveMinimum({ duration, minimumTime: 5000 });
let errorValue;
if (errorValue = guardDurationAboveMinimum({ duration, minimumTime: 5000 })) return errorValue;
return await effects.fetch(url)
.then((_) => ok)
@@ -33,11 +33,11 @@ export const guardDurationAboveMinimum = (
input: { duration: number; minimumTime: number },
) =>
(input.duration <= input.minimumTime)
? Promise.reject(errorCode(60, "Starting"))
? errorCode(60, "Starting")
: null;
export const catchError = (effects: Effects) => (e: unknown) => {
const error = (error: string) => ({ error });
effects.error(`Health check failed: ${e}`);
return error("Error while running health check");
};
};