Rejecting promises
See original GitHub issueI am getting empty error messages from the Requester:
responder
authService.on('getAdminToken', req => {
console.log('getAdminToken');
const adminToken = {
role: 'admin'
};
const options = {
audience: 'http://domain.com/audience',
expiresIn: '6 month'
}
return new Promise((resolve, reject) => {
const jwt = sign(adminToken, config.jwtSecret, options);
if(!jwt) reject(new Error('failed to sign token'));
resolve(jwt);
});
});
requester
requester.send({ type: 'getAdminToken' })
.then((token) => {
winston.info(token);
})
.catch(e => winston.error(e));
output
{
"level": "error",
"message": ""
}
I can’t see the problem. What did I get wrong with cote?
It also sends the empty message when I do:
authService.on('getAdminToken', req => {
return new Promise((resolve, reject) => {
reject(new Error('test error message'));
});
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Promise.reject() - JavaScript - MDN Web Docs
The Promise.reject() method returns a Promise object that is rejected with a given reason.
Read more >JavaScript promise reject() Method - GeeksforGeeks
The Promise.reject() method is used to return a rejected Promise object with a given reason for rejection. It is used for debugging purposes ......
Read more >JavaScript Promises - reject vs. throw - Stack Overflow
If it returns a rejected promise, the promise returned by the call to then is resolved to that promise (and will ultimately be...
Read more >JavaScript Promise Tutorial – How to Resolve or Reject ...
A Promise executor should call only one resolve or one reject . Once one state is changed (pending => fulfilled or pending =>...
Read more >Error handling with promises - The Modern JavaScript Tutorial
Promise chains are great at error handling. When a promise rejects, the control jumps to the closest rejection handler.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This seems much easier
No, cote doesn’t enforce any decision on your objects and your style. It just turns whatever you give to it into JSON, and it’s the user’s responsibility to make sure any object passed in can be serialized into JSON. cote is a tool with which you can implement any structure you wish, and in my projects in production, I use a custom Error JSON serializer for this.