diff options
author | Elizabeth Alexander Hunt <me@liz.coffee> | 2025-05-10 22:23:50 -0700 |
---|---|---|
committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2025-05-10 22:23:50 -0700 |
commit | 435c30da3f926cff5934e434824488e6c7a67ce6 (patch) | |
tree | 222a79e4b77dac6c20e4cf4a4251e7ccb8a50136 | |
parent | 739182bc8c04029cc324db22fcd201dfa2b93d43 (diff) | |
download | ci-435c30da3f926cff5934e434824488e6c7a67ce6.tar.gz ci-435c30da3f926cff5934e434824488e6c7a67ce6.zip |
Handle top level exceptions
-rwxr-xr-x | hooks/mod.ts | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/hooks/mod.ts b/hooks/mod.ts index ef44d25..cc29e43 100755 --- a/hooks/mod.ts +++ b/hooks/mod.ts @@ -19,35 +19,37 @@ Deno.serve(addr, async (req) => { const logger = getRequestLogger(req); logger.log("Request initiated"); - const { pathname } = new URL(req.url); - if (pathname === "/health") { - try { - getRequiredEnv("LAMINAR_HOST"); - await getStdout(["laminarc", "show-jobs"]); - return new Response("think im healthy. lets get to work.", { - status: 200, - }); - } catch (e) { - logger.error(e); - return new Response("i need to eat more vegetables -.-", { status: 500 }); + try { + const { pathname } = new URL(req.url); + if (pathname === "/health") { + try { + getRequiredEnv("LAMINAR_HOST"); + await getStdout(["laminarc", "show-jobs"]); + return new Response("think im healthy!! lets get to work.\n", { + status: 200, + }); + } catch (e) { + logger.error(e); + return new Response("i need to eat more vegetables -.-\n", { + status: 500, + }); + } } - } - - if (req.method !== "POST") { - return new Response("invalid method", { - status: 405, - }); - } - if (pathname === "/checkout_ci") { - const { remote, rev, refname } = await req.json(); - if (![remote, rev, refname].every(validateIdentifier)) { - return new Response("invalid request", { - status: 400, + if (req.method !== "POST") { + return new Response("invalid method", { + status: 405, }); } - try { + if (pathname === "/checkout_ci") { + const { remote, rev, refname } = await req.json(); + if (![remote, rev, refname].every(validateIdentifier)) { + return new Response("invalid request", { + status: 400, + }); + } + const laminar = await getStdout([ "laminarc", "queue", @@ -56,17 +58,17 @@ Deno.serve(addr, async (req) => { `rev="${rev}"`, `refname="${refname}"`, ]); - logger.log(`successful ci queue :D\n` + laminar); + logger.log(`successful queue :D\n` + laminar); return new Response(laminar, { status: 200, }); - } catch (e) { - logger.error(e); - return new Response("womp womp D:", { - status: 500, - }); } - } - return new Response("ahhhh idkkkk", { status: 404 }); + return new Response("idk what that is bro\n", { status: 404 }); + } catch (e) { + logger.error("Uncaught exception", e); + return new Response("womp womp D:\n", { status: 500 }); + } finally { + logger.log("Request finished."); + } }); |