feat: Add notification actions

This commit is contained in:
2024-01-26 08:48:27 +01:00
parent 2d2d47f55f
commit 0507722ecf
24 changed files with 1967 additions and 172 deletions

20
src/api.ts Normal file
View File

@@ -0,0 +1,20 @@
import { Response } from "node-fetch";
import { match } from "ts-pattern";
interface ResponseError {
message: string;
}
export async function handleErrors(response: Promise<Response>) {
return match(await response)
.with({ status: 400 }, async (r) => {
throw new Error(((await r.json()) as ResponseError).message);
})
.with({ status: 401 }, async (r) => {
throw new Error(((await r.json()) as ResponseError).message);
})
.with({ status: 500 }, async (r) => {
throw new Error(((await r.json()) as ResponseError).message);
})
.otherwise((resp) => resp);
}