I am developing an SOAP Server in NodeJS (v6.9.4) using the SOAP library. I have to request some data from a Postgres database. I choose to use the pg-promise lib.
SAOP Services are implemented like this :
TestConnection: function (args, cb, headers, req) {
db.any("select * from users where active=$1", [true])
.then(function (data) {
return {};
})
.catch(function (error) {
throw {
Fault: {
faultcode: faultCode,
faultstring: faultString,
detail: {
"ns:FaultInformation": {
"ns:FaultCode": detailedFaultCode,
"ns:FaultText": detailedFaultText
}
},
statusCode: 500
}
};
});
}
In case of error during the database connection/request, I need to return a SOAP Fault. On the SOAP lib, you can do this by throwing a new Fault object.
In this example, I want to throw it in the catch block. I know it's not the right way to do this and I am facing this issue :
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): [object Object]
How can I throw my SOAP Fault exception in the main service function. I tried without success the setTimeout solution. Is the promise a good solution for PG queries ?