UnhandledPromiseRejectionWarning in datatable for nodejs

UnhandledPromiseRejectionWarning in datatable for nodejs

aditimishraaditimishra Posts: 1Questions: 1Answers: 0
edited July 2018 in Free community support

I am using your datatable for node js ,everything is fine except it is giving me an error
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'data' of undefined,I dont know where I am wrong,I followed your example but its not wroking

 const routes = require('express').Router();
    //const con=require('../mysql.js');
    const passport = require('passport');
    const knex=require('../knex.js');
    let {
        Editor,
        Field,
        Validate,
        Format,
        Options
    } = require("datatables.net-editor-server");



    routes.get('/', (req, res) => {
      console.log(req.user);
      console.log(req.isAuthenticated());
      res.render('adminlogin')
      });
      routes.get('/dashboard', authenticationMiddleware (),(req, res) => {
        res.render('dashboard')
        });



        ///




      routes.post('/login',
        passport.authenticate('local', { failureRedirect: '/',successRedirect: '/dashboard' }));


          routes.get('/logout', (req, res) => {
            req.logout();
            req.session.destroy();
            res.redirect('/');
            });
            routes.all('/datatable', async function(err,req, res) {
              let editor = new Editor( knex, 'payment','id' )
              .fields(
                  new Field( 'name' ),
                  new Field( 'email' ),
                  new Field( 'amount' ),
                  new Field( 'customerid' ),
                  new Field( 'productname' ),
                  new Field( 'date_t' ),
                  new Field( 'address' ),
                  new Field( 'phone' ),
                  new Field( 'payment_id' ),
                  new Field( 'payment_status' ),
              );
        console.log(req.body);
              await editor.process(req.body);
        res.json( editor.data() );//this data is undefined here?? 
              });

            function authenticationMiddleware () {  
              return (req, res, next) => {
                console.log(`req.session.passport.user: ${JSON.stringify(req.session.passport)}`);

                  if (req.isAuthenticated()) return next();
                  res.redirect('/')
              }
            }

      module.exports = routes;

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    That's odd! What version of Node are you using?

    If you do console.log( editor); on the line before, what does the console show?

    Allan

This discussion has been closed.