wildflock/src/hooks/log-error.ts

18 lines
426 B
TypeScript
Raw Normal View History

2023-08-06 06:21:17 +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) => {
2023-08-06 06:21:17 +00:00
try {
await next();
} catch (error: any) {
logger.error(error.stack);
2023-07-29 18:10:00 +00:00
2023-08-06 06:21:17 +00:00
// Log validation errors
if (error.data) {
logger.error('Data: %O', error.data);
}
2023-07-29 18:10:00 +00:00
2023-08-06 06:21:17 +00:00
throw error;
}
2023-07-29 21:50:42 +00:00
};