Cote.js (promise) in Express
See original GitHub issueHi! I’m trying to use cote.js in my express app. Here my route code:
...
router.get('uuid', (req, res, next) => mainSvc.getUuid()
.then( data => res.json(data) )
.catch( next )
);
Here mainSvc code:
const cote = require('cote'),
uuidRequester = new cote.Requester({ name: 'uuid requester' });
module.exports = {
...
getUuid: ()=> {
const request = { type: 'uuid' };
return uuidRequester.send( request )
.then( data => {
console.log('Data:', data);
return data;
})
.catch( err => {
console.error('Error:', err);
return Promise.reject( err );
})
;
}
...
};
Here my service to generate uuid:
const uuid = require('uuid/v4'),
cote = require('cote'),
responder = new cote.Responder({ name: 'uuid responder' });
responder.on('uuid', (res, cb) => {
cb({ uuid: uuid() });
});
And in console I got error:
uuid requester > service.online uuid responder#47cdd6ce-ccfb-4043-bcf7-e01b54b1b626 on 8000 Error: { uuid: ‘e917380b-8128-4bd7-b087-3ed136987289’ }
What I did wrong and why I got Error instead Data? Thanks
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
dashersw/cote: A Node.js library for building zero ... - GitHub
a back-office with real-time updates for managing the catalogue of products and displaying sales with a RESTful API (express.js); a storefront for end-users ......
Read more >cote JavaScript and Node.js code examples - Tabnine
Best JavaScript code snippets using cote(Showing top 15 results out of 315) ... 'pending' } deliveries.push(delivery) return Promise.resolve(delivery) }).
Read more >Using Express.js Routes for Promise-based Error Handling
An Express.js route is a handler function corresponding to a given type of HTTP event matching a specified URI pattern. It's sent to...
Read more >Force MicroService to await until RabbitMQ publishes a ...
I have a an API-GATEWAY MicroService that manages the entire show , and one of the services is called QueueService. Here is the...
Read more >Using Promises with Express - Medium
The problem this function solves is that express doesn't natively handle promises, and so it doesn't support async / await . Route handlers...
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
@Keramet hello! Actually, it’s pretty simple. If you are using promises and callbacks together, you should make sure the first argument in the callback is the error object and it will be passed onto the
catch
handler, and the second argument is the actual result.In your case, a simple
cb(null, { uuid: uuid() });
would work. On the other hand, you can also useresponder.on('uuid', (res) => Promise.resolve({ uuid: uuid() }))
.@dashersw I think this should be highlighted more in the readme 😃