in MeteorJS : How to wrap in RVSP and chain using async await in Javascript?
- Dominant language
- JavaScript
- Stars
- 953
- Forks
- 164
- PR merge metrics
- No merged PRs in 30d
Description
# How to wrap in a Promise and chain the status code?
```
import unirest from 'unirest';
var RSVP = require('rsvp');
const callAsync = RSVP.denodeify(Meteor.call);
Meteor.method({
async myPutFunction() {
var promise = await new RSVP.Promise(function (resolve, reject) {
var unirest = require("unirest");
var req = unirest("PUT", "https://myURL");
req.headers({
"cache-control": "no-cache",
"content-type": "application/json",
"authorization": "Basic c2VjMxc6sdsXXXXXXXXX"
});
req.send("\r\n\r\n Test Description\r\n All Groups:TEMP CHANGE GROUP\r\n user\r\n");
req.end(function (res) {
if (res.error) reject(res.error);
resolve(this.response);
});
return promise;
}
});
async test() {
const res1 = await callAsync('someFunctionThatReturnsValue1'); // This is ok
const res2 = await callAsync('someFunctionThatReturnsValue2', res1); //This is ok, value #ok
const res3 = await callAsync('myPutFunction, res2) // status code 204 is not returned?
.then(txt => console.log('txt is :', txt)
.catch(reason => console.log('reason is : ', reason));
return res3;
}
Meteor.start({
callAsync('test');
});
```
But I don't get the status code returned? But promise codes?
I20160714-11:12:18.100(1)? txt is : { _45: 0,
I20160714-11:12:18.100(1)? _81: 3,
I20160714-11:12:18.100(1)? _65: { _45: 0, _81: 0, _65: null, _54: null },
I20160714-11:12:18.100(1)? _54: null }
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the Meteor.call and RSVP.denodeify flow shown in the report, then inspect the unirest req.end callback and its response value. Reproduce the request and verify whether the HTTP 204 status is exposed; done means the returned value is understood and the issue has a focused reproduction or confirmed resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100