I use http in
node to insert data into PotgreSQL table, in case of inserting data fails, such as the wrong column name, ... Node-RED side will make an error in postgres
node
while the browser side will still run without ending...
I would like when an error occurs with postgres
node, the browser side will display an error message such as insert data failed and end the response, is it possible?
I tried using catch
node to do this but it failed.
My flow:
[{"id":"7624b06e.61b2c","type":"http in","z":"1c4ec4d8.181d5b","name":"","url":"/insert","method":"get","upload":false,"swaggerDoc":"","x":2040,"y":220,"wires":[["1118246a.d4c26c"]]},{"id":"80cbeb16.13c6a8","type":"postgres","z":"1c4ec4d8.181d5b","postgresdb":"795c7d9.88a6f84","name":"","output":true,"outputs":1,"x":2360,"y":220,"wires":[["c701dbbd.2a9b78","7128a876.90b3f8"]]},{"id":"1118246a.d4c26c","type":"template","z":"1c4ec4d8.181d5b","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"INSERT INTO public.\"tblTest\"(fileName) VALUES ('File1.csv');","output":"str","x":2200,"y":220,"wires":[["80cbeb16.13c6a8"]]},{"id":"c701dbbd.2a9b78","type":"http response","z":"1c4ec4d8.181d5b","name":"http response","statusCode":"","headers":{},"x":2560,"y":220,"wires":[]},{"id":"7128a876.90b3f8","type":"debug","z":"1c4ec4d8.181d5b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2530,"y":260,"wires":[]},{"id":"124b177c.78c229","type":"catch","z":"1c4ec4d8.181d5b","name":"","scope":["80cbeb16.13c6a8"],"uncaught":false,"x":2030,"y":120,"wires":[["54a009fc.b5e728"]]},{"id":"51f4bfc6.714a1","type":"debug","z":"1c4ec4d8.181d5b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2550,"y":120,"wires":[]},{"id":"54a009fc.b5e728","type":"change","z":"1c4ec4d8.181d5b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Failed to insert data.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2200,"y":120,"wires":[["51f4bfc6.714a1","c701dbbd.2a9b78"]]},{"id":"795c7d9.88a6f84","type":"postgresdb","z":"","hostname":"localhost","port":"5432","db":"mydb","ssl":false}]
If possible, please tell me.
Thanks!