phantom phantom - 8 days ago 5
Javascript Question

request-promise error with response

I am using the

request-promise
library to implement promises with my API calls. I had previously been using the standard
request
library, and by parsing the
json
I was able to get the result I desired. However, since changing to the
request-promise
library I am getting an error saying
[SyntaxError: Unexpected token u]
.

Can anyone spot something I am doing wrong?

see code below:

var rp = require('request-promise');

var options = {
uri: 'https://api.filtr.com/3.0/Spotify/5/gb/tracks?tag=happy'
}

rp(options).then(function(error, response, body){
console.log(body);
var body = JSON.parse(body);
console.log(body);
}

Answer
var rp = require('request-promise');

var options = {
   uri: 'https://api.filtr.com/3.0/Spotify/5/gb/tracks?tag=happy'
}

rp(options).then(function(body){
  console.log(body)
})
.catch(function(error){
    console.log(error)
})
Comments