Node application crashing after receiving JSON, but not before sending it.

So I have a node.js application im trying to create, and part of it is reaching out to reddit's api and getting the JSON from a url, storing it in a URL and sending out what it gathered. It does all this but then after sending out the array of the objects it found, the application crashes with the error

    TypeError: Cannot read property 'children' of undefined

which doesnt make sense to me because it has already found those values and used them for the output. Any idea what could be wrong?

var express = require("express"),
restler = require("restler");

var app = express.createServer();

app.all('/:subreddit', function(req, res){
    restler.get("http://www.reddit.com/r/"+ req.params.subreddit + ".json").on('complete', function(reddit){
    var reddit_data = reddit.data.children;
    var titles = new Array();
    var i = 0;
    while (i<5){

        titles[i] = i+": " + reddit_data[i].data.title;
        i++
    }
    res.send(titles);
});
});

app.listen(14042);
console.log("redSMS listening on 14042");

The problem is that you take every request and pass it to Reddit.

If the browser goes to, say http://localhost/bmw, express will pass it to reddit and show the results for http://www.reddit.com/r/bmw.json. So far so good.

Then the browser does what it always does, goes for http://localhost/favicon.ico which passes to Reddit as http://www.reddit.com/r/favicon.ico.json, gives a 404 and no result. When you try to access children of that result, you get the crash.

The callback to the "complete" event handler gets passed 2 parameters, not one. The first is the "result", and the second is the "response" object.