B2G/gecko/services/aitc/modules/client.js
/**
   * GET request returned from getApps, process.
   */
GET request returned from getApps, process.
GET request returned from getApps process .
function _processGetApps(err, cb, req) {
    this._setBackoff(req);
    if (err) {
      this._log.error("getApps request error " + err);
      cb(err, null);
      return;
    }
    if (req.response.status == 401) {
      let msg = new Error("getApps failed due to 401 authentication failure");
      this._log.info(msg);
      msg.authfailure = true;
      cb(msg, null);
      return;
    }
    if (req.response.status == 304) {
      this._log.info("getApps returned 304");
      cb(null, null);
      return;
    }
    if (req.response.status != 200) {
      this._log.error(req);
      cb(new Error("Unexpected error with getApps"), null);
      return;
    }
    let apps;
    try {
      let tmp = JSON.parse(req.response.body);
      tmp = tmp["apps"];
      apps = tmp.map(this._makeLocalApp, this);
      this._log.info("getApps succeeded and got " + apps.length);
    } catch (e) {
      this._log.error(CommonUtils.exceptionStr(e));
      cb(new Error("Exception in getApps " + e), null);
      return;
    }
    try {
      cb(null, apps);
      this._appsLastModified = parseInt(req.response.headers["x-timestamp"], 10);
      this._state.set("lastModified", ""  + this._appsLastModified);
    } catch (e) {
      this._log.error("Exception in getApps callback " + e);
    }
  }
function _processGetApps ( err , cb , req ) { this . _setBackoff ( req ) ; if ( err ) { this . _log . error ( "getApps request error " + err ) ; cb ( err , null ) ; return ; } if ( req . response . status == 401 ) { let msg = new Error ( "getApps failed due to 401 authentication failure" ) ; this . _log . info ( msg ) ; msg . authfailure = true ; cb ( msg , null ) ; return ; } if ( req . response . status == 304 ) { this . _log . info ( "getApps returned 304" ) ; cb ( null , null ) ; return ; } if ( req . response . status != 200 ) { this . _log . error ( req ) ; cb ( new Error ( "Unexpected error with getApps" ) , null ) ; return ; } let apps ; try { let tmp = JSON . parse ( req . response . body ) ; tmp = tmp [ "apps" ] ; apps = tmp . map ( this . _makeLocalApp , this ) ; this . _log . info ( "getApps succeeded and got " + apps . length ) ; } catch ( e ) { this . _log . error ( CommonUtils . exceptionStr ( e ) ) ; cb ( new Error ( "Exception in getApps " + e ) , null ) ; return ; } try { cb ( null , apps ) ; this . _appsLastModified = parseInt ( req . response . headers [ "x-timestamp" ] , 10 ) ; this . _state . set ( "lastModified" , "" + this . _appsLastModified ) ; } catch ( e ) { this . _log . error ( "Exception in getApps callback " + e ) ; } }
GET request returned from getApps, process.
GET request returned from getApps process .
// Set X-Backoff or Retry-After, if needed. // Bubble auth failure back up so new token can be acquired. // Process response. // Convert apps from remote to local format. // Return success. // Don't update lastModified until we know cb succeeded.