title: Twitter API - If Rate limit exceeded
body: <p>I am developing a Twitter web app for myself. I am retrieving the latest trending topics.</p>
  
  <p>Here's how I'm doing it:</p>
  
  <pre><code>    $.ajax({
                        url: 'http://api.twitter.com/1/trends/1.json',
                        dataType: 'jsonp',
                         success: function(data){
  
  
                         $.each(data[0].trends, function(i){
                            $('div#trending').hide().append("&lt;p&gt;&lt;a href='"+data[0].trends[i].url+"'&gt;"+data[0].trends[i].name+"&lt;/a&gt;&lt;/p&gt;").fadeIn(1000);
                          //Cache into LocalStorage
                      localStorage["trending"+i] = data[0].trends[i].name; //Name
                      localStorage["trendurl"+i] = data[0].trends[i].url;//URL
  
                                  });
                              }
  });
  </code></pre>
  
  <p>But sometimes while I am developing it, the rate limit is exceeded.</p>
  
  <p>How can I detect if the rate limit has been exceeded?</p>
  
  <p>I cannot seem to detect if this error is being shown:</p>
  
  <pre><code>{"error":"Rate limit exceeded. Clients may not make more than 150 requests per hour.","request":"\/1\/trends\/1.json"}
  </code></pre>
  
  <p>I have tried it by:</p>
  
  <pre><code>success: function(data){
    if(data[0].error != 'undefined'){
      //load localstorage cache
    }
  }
  </code></pre>
  
  <p>But that doesn't seem to work.
  Please help.</p>
  
  <p>Thanks :)</p>