I am attempting to make an API call using the Netflix Roulette API and I've console logged the response to ensure I am retrieving info (which I am) but, I am still getting this error in the console:
Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING
I have been told this could be cause from a few things:
• Anti-virus software
• Google chrome browser settings
• Ensuring all responses have a response.end()
I have eliminated these causes to the best of my knowledge and I am still getting this error. Below is where I make the call:
var EventEmitter = require("events").EventEmitter;
var https = require("https");
var http = require("http");
var util = require("util");
var unirest = require('unirest');
/**
* An EventEmitter to get actor's Netflix info
* @param actor
* @constructor
*/
function Actor(actor) {
EventEmitter.call(this);
actorEmitter = this;
var request = unirest.get("https://community-netflix-roulette.p.mashape.com/api.php?actor=" + actor)
.header("X-Mashape-Key", "DHmuGLtqcomshyLbBKe5akHeFbN1p1UqyGmjsn7uCNpoDXhBXo")
.header("Accept", "application/json")
.end(function(response) {
var body = "";
if (response.statusCode !== 200) {
request.abort();
actorEmitter.emit("error", new Error("There was an error getting titles for " + actor.replace("%20", " ") + ". (" + http.STATUS_CODES[response.statusCode] + ")"));
}
response.on('data', function(chunk) {
body += chunk;
actorEmitter.emit("data", chunk);
});
response.on("end", function() {
if (response.statusCode === 200) {
try {
var actor = JSON.parse(body);
actorEmitter.emit("end", actor);
} catch (error) {
actorEmitter.emit("error", error);
}
}
}).on("error", function(error) {
actorEmitter.emit("error", error);
});
});
}
util.inherits(Actor, EventEmitter);
module.exports = Actor;
If you need more reference, here's a link to the repo:
via Martin Cartledge
No comments:
Post a Comment