editor.process(req.body); ERROR
editor.process(req.body); ERROR
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
Could you add:
To your Node program and let me know what it shows on the console.
Thanks,
Allan
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:
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 thereq.body
parameter is null or undefined.I don't see how that can be the case though, since you have:
and you mentioned that the body data was there.
Could you do:
and let me know the output please?
I'm just wondering if the body parser isn't decoding it?
Allan
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.
Got it - thanks!
I presume you have something like:
Could you enable the
extended
option for the body parser:The problem is that it isn't parsing the keys as nested data.
Allan
Hello Allan
It's working now.
Thank you so much for your good support.
KR
Sebastian