mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 10:21:55 +00:00
Merge pull request #9 from Start9Labs/update/catch-error
add health util for error catching
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
import { Effects, ResultType } from "./types.ts";
|
import { Effects, ResultType } from "./types.ts";
|
||||||
import { error, errorCode, ok } from "./util.ts";
|
import { error, errorCode, ok } from "./util.ts";
|
||||||
|
|
||||||
export const checkWebUrl: (
|
export const checkWebUrl: (
|
||||||
url: string,
|
url: string,
|
||||||
) => (effects: Effects, duration: number) => Promise<ResultType<null | void>> =
|
) => (effects: Effects, duration: number) => Promise<ResultType<null | void>> =
|
||||||
(url) => {
|
(url) => {
|
||||||
return async (effects, duration) => {
|
return async (effects, duration) => {
|
||||||
await guardDurationAboveMinimum({ duration, minimumTime: 5000 });
|
let errorValue;
|
||||||
|
if (errorValue = guardDurationAboveMinimum({ duration, minimumTime: 5000 })) return errorValue;
|
||||||
|
|
||||||
return await effects.fetch(url)
|
return await effects.fetch(url)
|
||||||
.then((_) => ok)
|
.then((_) => ok)
|
||||||
@@ -33,5 +33,5 @@ export const guardDurationAboveMinimum = (
|
|||||||
input: { duration: number; minimumTime: number },
|
input: { duration: number; minimumTime: number },
|
||||||
) =>
|
) =>
|
||||||
(input.duration <= input.minimumTime)
|
(input.duration <= input.minimumTime)
|
||||||
? Promise.reject(errorCode(60, "Starting"))
|
? errorCode(60, "Starting")
|
||||||
: null;
|
: null;
|
||||||
|
|||||||
Reference in New Issue
Block a user