Better handling for non-XML responses from Twitter #41

Open
kevinoid opened this Issue Jan 16, 2014 · 4 comments

Comments

Projects
None yet
4 participants

In certain failure conditions Twitter returns HTML (with the one-handed robot image) rather than an XML response for getOAuthAccessToken and/or getOAuthRequestToken. In this case passport-twitter will propagate an Error object with a message set to the HTML of the returned page, which is difficult to deal with and doesn't present well to users or in logs.

I would suggest that parseErrorResponse should return null in the case that body isn't well-formed XML and/or doesn't contain the expected elements so that '_createOAuthError' can return an Error with a more useful message. If the body is potentially useful, perhaps it could be added as a separate property of the Error object?

Thanks for considering,
Kevin

Owner

jaredhanson commented Jan 16, 2014

That'd be awesome. If you can provide a sample of this type of response (or a way to reproducible force it to happen), I'll add a test case for it. I've never seen such thing myself.

Sure. It's a very odd and rare indeed. We've been getting pretty high Twitter traffic and have only seen it twice so far. The content that Twitter sends is:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Language" content="en-us">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Twitter / Error</title>
    <link href="//abs.twimg.com/favicons/favicon.ico" rel="shortcut icon" type="image/x-icon">
    <link rel="stylesheet" href="//abs.twimg.com/errors/fullscreen_errors.css">
  </head>
  <body>
    <div class="topbar js-topbar">
      <div class="global-nav" data-section-term="top_nav">
        <div class="global-nav-inner">
          <div class="container">
            <ul class="nav js-global-actions">
              <li class="home">
                <a class="nav-logo-link" href="//twitter.com">
                  <i class="bird-topbar-blue"></i>
                </a>
              </li>
            </ul>
            <div class="pull-right">
              <ul class="nav secondary-nav">
                <li><a href="https://twitter.com" id="homeLink">Home &rarr;</a></li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="blue-sky">
      <div class="body-content">

          <div class="canvas">
            <img class= "illustration robot" src= "//abs.twimg.com/errors/robot.png" >
          </div>
          <h1>Something is technically wrong.</h1>
          <p>Thanks for noticing&mdash;we're going to fix it up and have things back to normal soon.</p>

        <div class="footer">
          <ul class="languages">

              <li><a data-language="cs" href="#">Čeština</a></li>

              <li><a data-language="ca" href="#">català</a></li>

              <li><a data-language="th" href="#">ภาษาไทย</a></li>

              <li><a data-language="nl" href="#">Nederlands</a></li>

              <li><a data-language="no" href="#">Norsk</a></li>

              <li><a data-language="tr" href="#">Türkçe</a></li>

              <li><a data-language="ar" href="#">العربية</a></li>

              <li><a data-language="ko" href="#">한국어</a></li>

              <li><a data-language="msa" href="#">Malay</a></li>

              <li><a data-language="he" href="#">עברית</a></li>

              <li><a data-language="hu" href="#">Magyar</a></li>

              <li><a data-language="zh-tw" href="#">繁體中文</a></li>

              <li><a data-language="hi" href="#">हिन्दी</a></li>

              <li><a data-language="en" href="#">English</a></li>

              <li><a data-language="xx-lc" href="#">LOLCATZ</a></li>

              <li><a data-language="el" href="#">Ελληνικά</a></li>

              <li><a data-language="eu" href="#">Euskara</a></li>

              <li><a data-language="es" href="#">Español</a></li>

              <li><a data-language="pt" href="#">português (Brasil)</a></li>

              <li><a data-language="pl" href="#">Polski</a></li>

              <li><a data-language="sq" href="#">shqip</a></li>

              <li><a data-language="be" href="#">беларуская</a></li>

              <li><a data-language="sv" href="#">Svenska</a></li>

              <li><a data-language="fil" href="#">Filipino</a></li>

              <li><a data-language="ja" href="#">日本語</a></li>

              <li><a data-language="ro" href="#">română</a></li>

              <li><a data-language="gl" href="#">Galego</a></li>

              <li><a data-language="ga" href="#">Gaeilge</a></li>

              <li><a data-language="ru" href="#">Русский</a></li>

              <li><a data-language="uk" href="#">Українська мова</a></li>

              <li><a data-language="ur" href="#">اردو</a></li>

              <li><a data-language="da" href="#">Dansk</a></li>

              <li><a data-language="de" href="#">Deutsch</a></li>

              <li><a data-language="zh-cn" href="#">简体中文</a></li>

              <li><a data-language="id" href="#">Indonesian</a></li>

              <li><a data-language="it" href="#">Italiano</a></li>

              <li><a data-language="fa" href="#">فارسی</a></li>

              <li><a data-language="fi" href="#">Suomi</a></li>

              <li><a data-language="fr" href="#">Français</a></li>

          </ul>
          <ul class="links">
            <li class="first">&copy; 2013 Twitter</li>
            <li><a href="https://twitter.com/about">About</a></li>
            <li><a href="https://support.twitter.com">Help</a></li>
            <li><a href="http://status.twitter.com/">Status</a></li>
          </ul>
        </div>
      </div>
    </div>

    <script src="//abs.twimg.com/errors/500-1b0419d1c7b999b1e664b1d3950b4e05.js"></script>
  </body>
</html> 

I'm not aware of a way to force it to occur. I'm guessing it only happens when Twitter is having a rather severe issue with their systems.

looveu commented Jan 27, 2015

same error

Same error here, and even cause out of memory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment