Tuesday 14 March 2017

API call is successfully made but, getting an error in the console

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_ENCODINGI 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 cause 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("http://ift.tt/2n7jc2u" + 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:Click here for repo

Submitted March 14, 2017 at 09:23PM by lacroix-boi

No comments:

Post a Comment