My current setup involves using Express to connect to my Teradata database, and everything works perfectly when there are no errors.
However, when an error occurs during a Teradata call, I can see the output in my console window but I'm unsure how to set up an error handler.
Although this seems like a basic issue, I am new to Express and would greatly appreciate any assistance.
Here is the code for the Express call:
router.post('/sp_run', function (req, res) {
var sql = "CALL DB.STORED_PROC1(1,P_ERROR_CODE,P_MSG);";
console.log(sql);
return teradata.read(sql)
.then((x) => {
console.log(x);
res.send(x);
});
});
This is the error information displayed in my console:
CALL DB.STORED_PROC1(1,P_ERROR_CODE,P_MSG);
express_1 | 2019-6-27 21:07:10 - error: [Teradata] Unable to execute query: CALL DB.STORED_PROC1(1,P_ERROR_CODE,P_MSG);
express_1 | Unhandled rejection Error: Error running instance method
express_1 | java.sql.SQLException: [Teradata Database] [TeraJDBC 16.20.00.10] [Error 7627] [SQLState HY000] STORED_PROC1:SELECT-INTO returned more than one row.
In case of an error, I want to send an email notification and provide a response to the frontend promptly instead of waiting indefinitely.