wildflock/src/hooks/log-error.ts

18 lines
390 B
TypeScript
Raw Normal View History

2023-07-29 21:50:42 +00:00
import type { HookContext, NextFunction } from "../declarations";
import { logger } from "../logger";
2023-07-29 18:10:00 +00:00
export const logError = async (context: HookContext, next: NextFunction) => {
try {
2023-07-29 21:50:42 +00:00
await next();
2023-07-29 18:10:00 +00:00
} catch (error: any) {
2023-07-29 21:50:42 +00:00
logger.error(error.stack);
2023-07-29 18:10:00 +00:00
// Log validation errors
if (error.data) {
2023-07-29 21:50:42 +00:00
logger.error("Data: %O", error.data);
2023-07-29 18:10:00 +00:00
}
2023-07-29 21:50:42 +00:00
throw error;
2023-07-29 18:10:00 +00:00
}
2023-07-29 21:50:42 +00:00
};