feat: Add notification actions
This commit is contained in:
20
src/api.ts
Normal file
20
src/api.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user