UnhandledRejection in nodejs
sanketzeeweesoft opened this issue · 3 comments
sanketzeeweesoft commented
I'm getting the unhandled rejection fatal error every time even applying catch to the method call:
My code:
Connect
.generateSession(
this.req.body.request_token,
process.env.ZERODHA_API_SECRET,
)
.catch((err) => {
throw err;
});
Error:
unhandledRejection {
status: 'error',
message: 'Token is invalid or has expired.',
data: null,
error_type: 'TokenException'
}
vividvilla commented
Seems like request_token
you are sending is invalid, log the toke and verify it.
sanketzeeweesoft commented
Seems like
request_token
you are sending is invalid, log the toke and verify it.
I know but my point is if I've added the catch method to the promise I should not get the unhandledRejection
self.generateSession = function(request_token, api_secret) {
var checksum = sha256(self.api_key + request_token + api_secret).toString();
var p = _post("api.token", {
api_key: self.api_key,
request_token: request_token,
checksum: checksum
}, null, formatGenerateSession);
p.then(function(response) {
self.setAccessToken(response.access_token);
}).catch(function(err) {
throw err
});
return p;
};
Please change the implementation of then
and catch
method which now attached after storing it in a variable i.e p
instead of applying it just after function call i.e.
var p = _post("api.token", {
api_key: self.api_key,
request_token: request_token,
checksum: checksum
}, null, formatGenerateSession).then(function(response) {
self.setAccessToken(response.access_token);
}).catch(function(err) {
throw err
});
vividvilla commented
This has been fixed on v3.2.0