title: how do I catch error in try catch by using winston in entire application?
body: <p><strong>winston.js</strong></p>
  
  <pre><code>
  var options = {
      file: {
          level: 'info',
          filename: `./app.log`,
          handleExceptions: true,
          json: true,
          colorize: false,
          timestamp:true
      },
      console: {
          level: 'debug',
          handleExceptions: true,
          json: false,
          colorize: true,
          timestamp:true
      },
  };
  
  // var logger = {}
  
  
  const logger = new winston.createLogger({
      transports: [
          new winston.transports.File(options.file),
          new winston.transports.Console(options.console)
      ],
      exceptionHandlers: [
          new winston.transports.File(options.file)
        ], 
      exitOnError: false, // do not exit on handled exceptions
  });
  
  logger.stream = {
      write: function(message, encoding) {
        // use the 'info' log level so the output will be picked up by both transports (file and console)
        logger.info(message);
        return;
      },
    };
  
    process.on('uncaughtException', function (err) {
        console.log('err',err)
      logger.error('uncaughtException', { message : err.message, stack : err.stack }); // logging with MetaData
      // process.exit(1); // exit with failure
  });
  
  process.on('unhandledRejection', (err, promise) =&gt; {
      logger.error('uncaughtException', { message : err.message, stack : err.stack }); // logging })
  });
  
  module.exports = logger;
  </code></pre>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>app.get('/data',async(req,res)=&gt;{
      try {
          let result = await config.data(req);
          console.log(result)
          res.status(200).json({
              code:200,
              message:'Success',
              data:result
          })
      } catch (error) {
          console.log(error.message)
      }
  })
  </code></pre>
  
  <p>This only handles the promise return error and uncaughtException error.</p>
  
  <p>I don't wanna put <code>logger.error()</code> in every try catch block.</p>
  
  <p>config.data() is not a function. I wanna catch this error automatically in the entire application.</p>
  
  <p>Someone please help me to solve this problem. I'm stuck at this point in the project.</p>