mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +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 { 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,5 +33,5 @@ export const guardDurationAboveMinimum = (
|
||||
input: { duration: number; minimumTime: number },
|
||||
) =>
|
||||
(input.duration <= input.minimumTime)
|
||||
? Promise.reject(errorCode(60, "Starting"))
|
||||
? errorCode(60, "Starting")
|
||||
: null;
|
||||
|
||||
Reference in New Issue
Block a user