editor.process(req.body); ERROR

editor.process(req.body); ERROR

LaSacreLaSacre Posts: 4Questions: 1Answers: 0

Hello,

I try to work work with the Editor Framework and it looks really good.
I have a NodeJs Express Aplliaction and can load data from my Oracle 11g DB.
Then I have implemented 3 Buttons ( create, edit and remove) and it works.
But when I click the edit Button the Form opens and a submit.
Here is where my trouble starts:
A error occure in my Console:
(node:7772) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot convert undefined or null to object
(node:7772) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I tried to print the some importent information into my console and found this:
This line make the trouble: await editor.process(req.body);
This are the values of the "req.body"

{ action: 'edit',
'data[row_E82554.1][LOTID]': 'E82554.1',
'data[row_E82554.1][PARTID]': '50515',
'data[row_E82554.1][FREIGABE]': 'HOLD' }

this is the function on my server:

router.all('/api/test01', async function(req, res) {
console.log("System call test01");
console.log(req.body);
let editor = new Editor(db, 'YE_MAP_CHECKLIST','LOTID').fields(
new Field("LOTID"),
new Field("PARTID"),
new Field("FREIGABE"),
);
console.log("ERROR?");
console.log(req.body);
await editor.process(req.body);
console.log(editor.data());
res.json(editor.data());
});

This is my db.js file:

let knex = require('knex');
let oracledb = require('oracledb');

module.exports = knex({
client: 'oracledb',
connection: {
connectString : "xxxx",
password: 'xxxx',
user: 'xxxx',
dateStrings: true
}
});

Thank you for helping

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 48,097Questions: 1Answers: 6,917 Site admin
    Answer ✓

    Could you add:

    process.on( 'unhandledRejection', (reason, p) => {
        log.log( 'Unhandled promise error A:  ', p );
        log.error( 'Unhandled promise error B:  ', reason );
    } );
    

    To your Node program and let me know what it shows on the console.

    Thanks,
    Allan

  • LaSacreLaSacre Posts: 4Questions: 1Answers: 0
    edited April 13

    Hello allan

    I hope this is the information you are looking for.
    Your code is not working, I implemented:

    process.on( 'unhandledRejection', (reason, p) => {
    console.log( 'Unhandled promise error A: ', p );
    console.error( 'Unhandled promise error B: ', reason );
    } );
    Is this ok? Or do I need e requirement for log?
    Something like: let log = require("debug");

    This is my error Code:

    Unhandled promise error B:   TypeError: Cannot convert undefined or null to object
    Unhandled promise error A:   Promise {
        at Function.keys (<anonymous>)
      <rejected> TypeError: Cannot convert undefined or null to object
        at Editor.<anonymous> (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:1136:39)
        at Function.keys (<anonymous>)
        at Editor.<anonymous> (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:1136:39)
        at step (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:42:23)
        at step (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:42:23)
        at Object.next (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:23:53)
        at Object.next (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:23:53)
        at C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:17:71
        at C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:17:71
        at new Promise (<anonymous>)
        at new Promise (<anonymous>)
        at __awaiter (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:13:12)
        at __awaiter (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:13:12)
        at Editor._process (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:1086:16)
        at Editor._process (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:1086:16)
        at C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:427:75
        at C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:427:75
        at step (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:42:23)
        at step (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:42:23)
        at Object.next (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:23:53)
        at Object.next (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:23:53)
        at C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:17:71
        at new Promise (<anonymous>)
        at C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:17:71
        at new Promise (<anonymous>)
        at __awaiter (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:13:12)
        at __awaiter (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:13:12)
        at run (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:409:36)
        at run (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:409:36)
        at Editor.<anonymous> (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:455:50) }
        at Editor.<anonymous> (C:\Git_Repositories\NodeJs\YE_MAP_Checklist_02\node_modules\datatables.net-editor-server\dist\editor.js:455:50)
    
  • allanallan Posts: 48,097Questions: 1Answers: 6,917 Site admin
    Answer ✓

    Sorry! I copied and pasted it from one of my own scripts and I forgot to update it to use the console.

    The error is suggesting that there is nothing in the data property submitted to the server - or more accurately that the req.body parameter is null or undefined.

    I don't see how that can be the case though, since you have:

    console.log(req.body);
    await editor.process(req.body);
    

    and you mentioned that the body data was there.

    Could you do:

    console.log( typeof req.body );
    console.log( JSON.stringify( req.body ) );
    

    and let me know the output please?

    I'm just wondering if the body parser isn't decoding it?

    Allan

  • LaSacreLaSacre Posts: 4Questions: 1Answers: 0

    Hey

    my code in the project:
    console.log("Typeof: "+ typeof req.body );
    console.log("Data: " +JSON.stringify( req.body ) );

    the console output:

    Typeof: object
    Data: {"action":"edit","data[row_E82554.1][LOTID]":"E8255","data[row_E82554.1][PARTID]":"505","data[row_E82554.1][FREIGABE]":"HO"}

    (node:3416) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot convert undefined or null to object
    (node:3416) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

  • allanallan Posts: 48,097Questions: 1Answers: 6,917 Site admin
    Answer ✓

    Got it - thanks!

    I presume you have something like:

    app.use( bodyParser.urlencoded() );
    

    Could you enable the extended option for the body parser:

    app.use( bodyParser.urlencoded({ extended: true }) );
    

    The problem is that it isn't parsing the keys as nested data.

    Allan

  • LaSacreLaSacre Posts: 4Questions: 1Answers: 0

    Hello Allan

    It's working now.
    Thank you so much for your good support.

    KR
    Sebastian

Sign In or Register to comment.