log-error.ts 481 B

123456789101112131415161718
  1. // For more information about this file see https://dove.feathersjs.com/guides/cli/log-error.html
  2. import type { HookContext, NextFunction } from '../declarations'
  3. import { logger } from '../logger'
  4. export const logError = async (context: HookContext, next: NextFunction) => {
  5. try {
  6. await next()
  7. } catch (error: any) {
  8. logger.error(error.stack)
  9. // Log validation errors
  10. if (error.data) {
  11. logger.error('Data: %O', error.data)
  12. }
  13. throw error
  14. }
  15. }