requestFcn()

in core/routemgmt/common/apigw-utils.js [210:233]


    requestFcn(options, function(error, response, body) {
      var statusCode = response ? response.statusCode : undefined;
      console.log('addApiToGateway: response status:'+ statusCode);
      if (error) console.error('Warning: addRouteToGateway request failed: '+ makeJsonString(error));
      if (response && response.headers) console.log('addApiToGateway: response headers: '+makeJsonString(response.headers));
      if (body) console.log('addApiToGateway: response body: '+makeJsonString(body));
      if (error) {
        console.error('addApiToGateway: Unable to configure the API Gateway');
        reject('Unable to configure the API Gateway: '+makeJsonString(error));
      } else if (statusCode != 200) {
        if (body) {
          var errMsg = makeJsonString(body);
          if (body.error && body.error.message) errMsg = body.error.message;
          reject('Unable to configure the API Gateway (status code '+statusCode+'): '+ errMsg);
        } else {
          reject('Unable to configure the API Gateway: Response failure code: '+statusCode);
        }
      } else if (!body) {
        console.error('addApiToGateway: Unable to configure the API Gateway: No response body');
        reject('Unable to configure the API Gateway: No response received from the API Gateway');
      } else {
        resolve(body);
      }
    });