title: http statusCode sometimes undefined
body: <p>I'm using request module in my node.js(express) application. Sometimes this statusCode related error occurs:</p>
  
  <pre><code>TypeError: Cannot read property
  'statusCode' of undefined at Request._callback
  </code></pre>
  
  <p>This is my whole code:</p>
  
  <pre><code>request("https://www.googleapis.com/youtube/v3/search?part=snippet&amp;q=" + docs[0].title + "&amp;type=video&amp;key=(some-key-variable)", {
                  json: true
                }, function(error, response, resultData) {
                  var yArr = [];
                  if (!error || response.statusCode == 200) {
                    for (var i = 0; i &lt; config.youtubeVideoCount; i++) {
                      var vArr = resultData.items[i];
                      yArr.push(vArr);
                    }
                  } else {
                    console.log("can't find video");
                  }
                });
  </code></pre>
  
  <p><code>response.statusCode</code> gives an error sometimes. How can I control that the request is successful? Is it bug in the request module? Why is statusCode undefined sometimes? I think statusCode should be available every time.</p>
  
  <p><strong>Answer</strong>
  Probably it is response timeout issue and u should do an if statement like this;</p>
  
  <pre><code>if (response === undefined || response.statusCode != 200){ console.log("there is a prob"); }
  </code></pre>
  
  <p>this code firstly control response variable and then response.statuscode , so if response undefined don't control response.statusCode thus , we can't get any error.</p>