python -> node.js
This commit is contained in:
parent
092f2ec0f3
commit
395fba645d
62 changed files with 726 additions and 1702 deletions
29
functions/generate_minutes/src/logics/error.ts
Normal file
29
functions/generate_minutes/src/logics/error.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { Response } from "express";
|
||||
import z from "zod";
|
||||
import { ERROR_DEFINITIONS, ErrorKey } from "../stores/errorCodes";
|
||||
|
||||
const CustomErrorSchema = z.object({
|
||||
code: z.string(),
|
||||
message: z.string(),
|
||||
statusCode:z.number(),
|
||||
});
|
||||
|
||||
export type CustomError = z.infer<typeof CustomErrorSchema>;
|
||||
|
||||
export const createCustomError = (key: ErrorKey): CustomError => {
|
||||
const errorInfo = ERROR_DEFINITIONS[key];
|
||||
return CustomErrorSchema.parse(errorInfo);
|
||||
};
|
||||
|
||||
export const responseError = (error: any, res: Response | null = null) => {
|
||||
if (!CustomErrorSchema.safeParse(error).success) {
|
||||
console.error(error);
|
||||
console.error("========== Unknown Error ==========");
|
||||
if(res) return res.status(500).send('Internal Server Error');
|
||||
}
|
||||
const parsedError = CustomErrorSchema.parse(error);
|
||||
console.error("========== Custom Error ==========");
|
||||
console.error(`Error Code: ${parsedError.code}\n Message: ${parsedError.message}`);
|
||||
if(res) return res.status(parsedError.statusCode).send(parsedError.message);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue