responseStatus
take a response and check the response `status` property
if between 200-300 return the response object
else throw a custom error
@param  {Object} res
@return {Object}
352529
function responseStatus(res) {
  if (res.status >= 200 && res.status < 300) {
    return res;
  } else {
    var error = new Error(res.statusText);
    error.response = res;
    throw customError('responseStatus', error);
  }
}
415458
function parseError(res, body) {
  // Res is optional.
  if (body == null) {
    body = res;
  }
  // Status code is required.
  const status = parseError.findErrorCode(sliced(arguments));
  if (!status) {
    return false;
  }
  // Body can have an error-like object, in which case the attributes will be used.
  const obj = findErrorObj(body);
  if (obj) {
    body = Object.assign(body, obj);
  }
  return [status, body];
}
1153448
function checkHttpCode(expected, res, body, callback) {
  if (res.statusCode !== expected) {
    if (!body) {
      return callback(new Error(format('Unexpected deis response (expected %s but %s was returned)', expected, res.statusCode)));
    }

    var error = body.hasOwnProperty('detail') ?
        body.detail : JSON.stringify(body);

    return callback(new Error(error));
  }

  return callback(null, body);
}
189923
def _get_response_json(self, res):
        

        try:
            error = res.json()
        except ValueError:
            error = {
                "message": "The API did not respond with JSON, but: {0}".format(res.text[:1000]),
                "error_code": "{0}".format(res.status_code)
            }
        return error
856952
function _getResponseStatus(handler, req, callback) {
        // Number
        if (!_(handler.reply.status).isFunction()) {
            return callback(handler.reply.status || 0);
        }

        // Synch function
        return callback(handler.reply.status(req) || 0);
    }
13450
function sendError(res,err) {
    console.error(err);
    // also log last executed query, for easier debugging
    console.error(lastQry.sql);
    res.statusCode = 500;
    res.send({
        result: 'error',
        err:    err
    });
}
1365600
function (req, res) {
    User.find().exec(function (err, users) {
      if(err) return res.json({ err: err }, 500);
      else res.json(users);
    });
  }
738995
def parse_response(resp):
        
        if resp.status_code in [200, 201, 202]:
            return resp.json()
        elif resp.status_code == 204:
            return None
        elif resp.status_code == 400:
            raise error.BadRequestError(resp.text)
        elif resp.status_code == 401:
            raise error.UnauthorizedError(resp.text)
        elif resp.status_code == 403:
            raise error.ForbiddenError(resp.text)
        elif resp.status_code == 404:
            raise error.NotFoundError(resp.text)
        elif resp.status_code == 429:
            raise error.TooManyRequestsError(resp.text)
        elif resp.status_code == 503:
            raise error.ServiceUnavailableError(resp.text)
        else:
            raise error.OptimizelyError(resp.text)
1193671
function formatResponse (res) {
    // iterate over rows in response
    _.each(res, row => {
        // iterate over key/value pairs in row object
        _.each(row, (val, key) => {
            // convert nulls to undefined
            if (val === null) {
                row[key] = undefined
            }
        })
    })
}
1255720
function sendStatus(code, res){
	try{
		if (httpCodeMapping) {
			code = mapHttpStatusCode(code);
		}
		addStrictTransportHeaders(res);
		setResponseNoCache(res);
		return res.sendStatus(code);
	}catch(err){
		logger.error(res.req.originalUrl , err.message);
		throw err;
	}
}
693660
function handleResponse(done, err, response, body) {
  if (err) return done(err, null);
  if (response.statusCode !== 200) return done(new Error(body.msg || 'Unknown error'), null);

  done(null, body);
}
1115793
function (res, res_obj) {

    // return response if exist, otherwise response might be returned 
    // AFTER some callback is done handling (i.e., response will be returned within the handler)
    if (typeof res_obj === 'string') {
        LOG.sys('replying a string: ' + res_obj);
        res.writeHead(200, {'Content-Type': 'text/plain'});                     
        res.end(res_obj);            
    }
    else {
        LOG.sys('replying a JSON: ' + JSON.stringify(res_obj));
        res.writeHead(200, {'Content-Type': 'application/json'});                     
        res.end(JSON.stringify(res_obj));        
    }
}
512301
def _error_handling(self, res):
        

        # making the error handling generic so if an status_code starting with 2 doesn't exist, we raise the error
        if res.status_code // 100 != 2:
            error = self._get_response_json(res)
            raise exceptions.KeenApiError(error)
59166
function checkResponseForErrors(res) {
    let { statusCode, body, headers } = res;

    if (statusCode >= 400) {
        return { error: true, body };
    }

    // API key is invalid
    if ((body.error) && (body.error === 'Unauthorized')) {
        return { error: true, body };
    }

    // response is not json
    if (headers['content-type'] !== 'application/json; charset=utf-8') {
        return { error: true, body: { error: 'JSON expected' } };
    }

    return { error: false, body };
}
288059
function WrappedResponse(msg, hdr, err, res) {
  this._msg = msg;
  this.headers = hdr;
  this.error = err;
  this.response = res;
}
178836
def handle_response(response)
      case response.code.to_i
        when 301,302
          raise "Redirect"
        when 200...400
          response
        when 400
          raise "Bad Request"
        when 401
          raise "Unauthorized Access"
        when 403
          raise "Forbidden Access"
        when 404
          raise "Rescoure not found"
        when 405
          raise "Method not allowed"
        when 409
          raise RequestError.new("Rescource conflict")
        when 422
          raise RequestError.new("Resource invalid")
        when 401...500
          raise "Client error"
        when 500...600
          raise RequestError.new("Server error")
        else
          raise "Unknown response: #{response.code.to_i}"
      end
    end
369803
function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
                return cb(null, JSON.parse(xhr.response));
            }
            cb('error requesting ' + uri);
        }