Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

martin cartledge
martin cartledge
1,933 Points

Getting `Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING` error...

I am using the Netflix Roulette API with my Node js app and I'm getting this error in the browser:

Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING

I have console logged the response and successfully get the JSON that I searched for but, nothing displays in the browser.

Here is where I make the call:

var EventEmitter = require("events").EventEmitter;
var https = require("https");
var http = require("http");
var util = require("util");
var apiKey = require('../.ENV');
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;