handleSuccessResponse(response, endpoint) {

    let data = response._body || '';

    if (endpoint.contextOptions.decodeHtmlEntities) {
      data = he.decode(data);
    }

    // Attempt to parse some JSON, otherwise continue on (may be empty, or text)
    try {
      data = JSON.parse(data);

      // Reddit isn't always honest in their response status. Check for
      // any errors in 2xx http statuses

      // data.json.errors
      if (data.json && data.json.errors && data.json.errors.length > 0) {
        return when.reject(new ResponseError('', response, endpoint));
      }

      // data.json.error
      if (data.json && data.json.error) {
        return when.reject(new ResponseError('', response, endpoint));
      }

    } catch(e) {}


    let rateLimitRemaining = response._headers['x-ratelimit-remaining'];
    let rateLimitUsed = response._headers['x-ratelimit-used'];
    let rateLimitReset = response._headers['x-ratelimit-reset'];

    let rateLimitData = {
      rateLimitRemaining: rateLimitRemaining ? Number(rateLimitRemaining) : void 0,
      rateLimitUsed: rateLimitUsed ? Number(rateLimitUsed) : void 0,
      rateLimitReset: rateLimitReset ? Number(rateLimitReset) : void 0
    };

    if (typeof rateLimitData.rateLimitUsed !== 'undefined') {
      this.emit('rate_limit', rateLimitData);
    }

    // Using a test variable
    // this._userConfig.__test.rateLimitRemainingCutoff
    // it's default value is "0", however in the tests cases this
    // would take too long.
    let cutoff = this._userConfig.__test.rateLimitRemainingCutoff;

    if (typeof rateLimitData.rateLimitRemaining !== 'undefined' &&
      Number(rateLimitRemaining) <= cutoff)
    {
      this.emit('rate_limit_reached', rateLimitData);
    }

    if (this._userConfig.useBrowserCookies && data.data &&
        data.data.modhash && data.data.modhash.length) {
      this._modhash.setModhash(data.data.modhash);
    }

    return when.resolve(data);
  }
/*
     Handle reddit response status of 2xx.

     Finally return the data if there were no problems.
   */
Handle reddit response status of 2xx.
Finally return the data if there were no problems.
Handle reddit response status of 2xx . Finally return the data if there were no problems .
handleSuccessResponse(response, endpoint) {
    let data = response._body || '';
    if (endpoint.contextOptions.decodeHtmlEntities) {
      data = he.decode(data);
    }
    try {
      data = JSON.parse(data);
      if (data.json && data.json.errors && data.json.errors.length > 0) {
        return when.reject(new ResponseError('', response, endpoint));
      }
      if (data.json && data.json.error) {
        return when.reject(new ResponseError('', response, endpoint));
      }
    } catch(e) {}
    let rateLimitRemaining = response._headers['x-ratelimit-remaining'];
    let rateLimitUsed = response._headers['x-ratelimit-used'];
    let rateLimitReset = response._headers['x-ratelimit-reset'];
    let rateLimitData = {
      rateLimitRemaining: rateLimitRemaining ? Number(rateLimitRemaining) : void 0,
      rateLimitUsed: rateLimitUsed ? Number(rateLimitUsed) : void 0,
      rateLimitReset: rateLimitReset ? Number(rateLimitReset) : void 0
    };
    if (typeof rateLimitData.rateLimitUsed !== 'undefined') {
      this.emit('rate_limit', rateLimitData);
    }
    let cutoff = this._userConfig.__test.rateLimitRemainingCutoff;
    if (typeof rateLimitData.rateLimitRemaining !== 'undefined' &&
      Number(rateLimitRemaining) <= cutoff)
    {
      this.emit('rate_limit_reached', rateLimitData);
    }
    if (this._userConfig.useBrowserCookies && data.data &&
        data.data.modhash && data.data.modhash.length) {
      this._modhash.setModhash(data.data.modhash);
    }
    return when.resolve(data);
  }
handleSuccessResponse ( response , endpoint ) { let data = response . _body || '' ; if ( endpoint . contextOptions . decodeHtmlEntities ) { data = he . decode ( data ) ; } try { data = JSON . parse ( data ) ; if ( data . json && data . json . errors && data . json . errors . length > 0 ) { return when . reject ( new ResponseError ( '' , response , endpoint ) ) ; } if ( data . json && data . json . error ) { return when . reject ( new ResponseError ( '' , response , endpoint ) ) ; } } catch ( e ) { } let rateLimitRemaining = response . _headers [ 'x-ratelimit-remaining' ] ; let rateLimitUsed = response . _headers [ 'x-ratelimit-used' ] ; let rateLimitReset = response . _headers [ 'x-ratelimit-reset' ] ; let rateLimitData = { rateLimitRemaining : rateLimitRemaining ? Number ( rateLimitRemaining ) : void 0 , rateLimitUsed : rateLimitUsed ? Number ( rateLimitUsed ) : void 0 , rateLimitReset : rateLimitReset ? Number ( rateLimitReset ) : void 0 } ; if ( typeof rateLimitData . rateLimitUsed !== 'undefined' ) { this . emit ( 'rate_limit' , rateLimitData ) ; } let cutoff = this . _userConfig . __test . rateLimitRemainingCutoff ; if ( typeof rateLimitData . rateLimitRemaining !== 'undefined' && Number ( rateLimitRemaining ) <= cutoff ) { this . emit ( 'rate_limit_reached' , rateLimitData ) ; } if ( this . _userConfig . useBrowserCookies && data . data && data . data . modhash && data . data . modhash . length ) { this . _modhash . setModhash ( data . data . modhash ) ; } return when . resolve ( data ) ; }
Handle reddit response status of 2xx.
Handle reddit response status of 2xx .
// Attempt to parse some JSON, otherwise continue on (may be empty, or text) // Reddit isn't always honest in their response status. Check for // any errors in 2xx http statuses // data.json.errors // data.json.error // Using a test variable // this._userConfig.__test.rateLimitRemainingCutoff // it's default value is "0", however in the tests cases this // would take too long.