Issue
I don't know why this errors kept coming. I searched for all possible solutions on the internet still I didn't find any. Here is my node function for API call:
exports.GetEmployeeConfirmationList = function (req, res) {
var request = dbConn.request();
request.execute(storedProcedures.GetEmployeeConfirmationList).then(function (response) {
res.status(200).send({
success: true,
data: response.recordset
});
}).catch(function (err) {
res.status(200).send({
success: false,
message: err.message
});
});
};
How to overcome this problem?
Solution
Modify your code to use arrow function as res
object is losing its scope.
When GetEmployeeConfirmationList
callback is called it doesn't know about res
object hence undefined
for it. So while executing res.status
it throws an exception and comes in catch
block, where it again executes res.status
and it breaks again and leads to Unhandled promise rejection.
You can capture the err
object and log
it in finally
block to check if it is happening so.
exports.GetEmployeeConfirmationList = function (req, res) {
var request = dbConn.request();
request.execute(storedProcedures.GetEmployeeConfirmationList).then((response) => {
res.status(200).send({
success: true,
data: response.recordset
});
}).catch((err) => {
res.status(200).send({
success: false,
message: err.message
});
});
};
Answered By - Suresh Prajapati
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.