Promise-based Wrapper for Simple HTTP Requests built on top of Bluebird and Request
request
README wouldn’t work.
vue-resource
community.
request-promise
library only. The vue.js community has a forum for your type of question: https://forum.vuejs.org They’ll be able to help you.
request-promise
but forgot to put a return in front of the call to request
so the cookie was getting updated, but because I wasn't waiting on the promise to resolve, I had authentication errors.
body
or request
out of await
ing a call to request
. I don't know if I was just doing something wrong or if I really can't await
request
. Would be really cool if one could do this though. It would make testing code a lot cleaner
firsturl = 'someurl.json';
secondurl = 'some_second_url.json';
request = require('request-promise');
options = {
url: firsturl,
json: false,
header: "some_username_password"
}
request(options)
.then(function(data1) {
var data_first = JSON.parse(data1); //results from the first url
options.url = secondurl;
request(options)
.then(function(data2) {
var data_second = JSON.parse(data2);
console.log(data_second);
//why it prints the results from the first url???
})
})
await rp(…)
you could use await rp(…).promise()
. Since rp(…)
returns a mixed object that is a certain request object and a promise at the same time that may confuse the runtime. .promise()
returns just the promise and that should definitely work with await
.
So my code looks like this
return rp(options)
.then(response => {
let timeEntries = JSON.parse(response)['time-entries'];
return timeEntries;
})
.catch(err => console.log(err.MESSAGE));
Which is a part of a method.
I am getting this error Unhandled rejection Error: StatusCodeError: 400 - "{\"MESSAGE\":\"Invalid Parameters - 'page' must be greater or equal to 1\",\"STATUS\":\"Error\"}"
then
and catch
in the snippet is perfect. The only explanation I currently have for your unhandled rejection is that you actual code doesn’t match the snippet. Or the rejection came from a different request at another spot in your code. Could you double check?