question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rejecting promises

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
robophilcommented, Aug 30, 2017

This seems much easier

JSON.stringify(err, Object.getOwnPropertyNames(err))
0reactions
dasherswcommented, Aug 30, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found