lib/services/sf.js
function sendHttpRequest(requestOptions, httpClient)
  {
    return httpClient.request(
    {
      method   : requestOptions.method,
      headers  : requestOptions.headers,
      url      : requestOptions.absoluteUrl,
      gzip     : requestOptions.gzip,
      json     : requestOptions.json,
      callback : function(err, response, body)
      {
        // if we got an error, wrap it into a network error
        if (err)
        {
          err = Errors.createNetworkError(
              ErrorCodes.ERR_SF_NETWORK_COULD_NOT_CONNECT, err);
        }
        // if we didn't get a 200, the request failed
        else if (!response || response.statusCode !== 200)
        {
          err = Errors.createRequestFailedError(
              ErrorCodes.ERR_SF_RESPONSE_FAILURE, response);
        }
        else
        {
          // if the response body is a non-empty string and the response is
          // supposed to contain json, try to json-parse the body
          if (Util.isString(body) &&
              response.getResponseHeader('Content-Type') === 'application/json')
          {
            try
            {
              body = JSON.parse(body);
            }
            catch (parseError)
            {
              // we expected to get json
              err = Errors.createUnexpectedContentError(
                  ErrorCodes.ERR_SF_RESPONSE_NOT_JSON, response.body);
            }
          }

          // if we were able to successfully json-parse the body and the success
          // flag is false, the operation we tried to perform failed
          if (body && !body.success)
          {
            var data = body.data;
            err = Errors.createOperationFailedError(
                body.code, data, body.message,
                data && data.sqlState ? data.sqlState : undefined);
          }
        }

        // if we have an error, clear the body
        if (err)
        {
          body = undefined;
        }

        // if a callback was specified, invoke it
        if (Util.isFunction(requestOptions.callback))
        {
          requestOptions.callback.apply(requestOptions.scope, [err, body]);
        }
      }
    });
  }
function sendHttpRequest(requestOptions, httpClient)
  {
    return httpClient.request(
    {
      method   : requestOptions.method,
      headers  : requestOptions.headers,
      url      : requestOptions.absoluteUrl,
      gzip     : requestOptions.gzip,
      json     : requestOptions.json,
      callback : function(err, response, body)
      {
        // if we got an error, wrap it into a network error
        if (err)
        {
          err = Errors.createNetworkError(
              ErrorCodes.ERR_SF_NETWORK_COULD_NOT_CONNECT, err);
        }
        // if we didn't get a 200, the request failed
        else if (!response || response.statusCode !== 200)
        {
          err = Errors.createRequestFailedError(
              ErrorCodes.ERR_SF_RESPONSE_FAILURE, response);
        }
        else
        {
          // if the response body is a non-empty string and the response is
          // supposed to contain json, try to json-parse the body
          if (Util.isString(body) &&
              response.getResponseHeader('Content-Type') === 'application/json')
          {
            try
            {
              body = JSON.parse(body);
            }
            catch (parseError)
            {
              // we expected to get json
              err = Errors.createUnexpectedContentError(
                  ErrorCodes.ERR_SF_RESPONSE_NOT_JSON, response.body);
            }
          }

          // if we were able to successfully json-parse the body and the success
          // flag is false, the operation we tried to perform failed
          if (body && !body.success)
          {
            var data = body.data;
            err = Errors.createOperationFailedError(
                body.code, data, body.message,
                data && data.sqlState ? data.sqlState : undefined);
          }
        }

        // if we have an error, clear the body
        if (err)
        {
          body = undefined;
        }

        // if a callback was specified, invoke it
        if (Util.isFunction(requestOptions.callback))
        {
          requestOptions.callback.apply(requestOptions.scope, [err, body]);
        }
      }
    });
  }
function sendHttpRequest ( requestOptions , httpClient ) { return httpClient . request ( { method : requestOptions . method , headers : requestOptions . headers , url : requestOptions . absoluteUrl , gzip : requestOptions . gzip , json : requestOptions . json , callback : function ( err , response , body ) { // if we got an error, wrap it into a network error if ( err ) { err = Errors . createNetworkError ( ErrorCodes . ERR_SF_NETWORK_COULD_NOT_CONNECT , err ) ; } // if we didn't get a 200, the request failed else if ( ! response || response . statusCode !== 200 ) { err = Errors . createRequestFailedError ( ErrorCodes . ERR_SF_RESPONSE_FAILURE , response ) ; } else { // if the response body is a non-empty string and the response is // supposed to contain json, try to json-parse the body if ( Util . isString ( body ) && response . getResponseHeader ( 'Content-Type' ) === 'application/json' ) { try { body = JSON . parse ( body ) ; } catch ( parseError ) { // we expected to get json err = Errors . createUnexpectedContentError ( ErrorCodes . ERR_SF_RESPONSE_NOT_JSON , response . body ) ; } } // if we were able to successfully json-parse the body and the success // flag is false, the operation we tried to perform failed if ( body && ! body . success ) { var data = body . data ; err = Errors . createOperationFailedError ( body . code , data , body . message , data && data . sqlState ? data . sqlState : undefined ) ; } } // if we have an error, clear the body if ( err ) { body = undefined ; } // if a callback was specified, invoke it if ( Util . isFunction ( requestOptions . callback ) ) { requestOptions . callback . apply ( requestOptions . scope , [ err , body ] ) ; } } } ) ; }
Issues an http request to Snowflake.

@param {Object} requestOptions
@param {Object} httpClient

@returns {Object} the http request object.
Issues an http request to Snowflake .