static requestPromise()

in templates/nodejs/src/http.js [93:127]


  static requestPromise(
    method: string,
    url: string,
    data: Object,
    files: Object,
    useMultipartFormData: Boolean = false,
    showHeader: Boolean = false,
  ): Promise<*> {
    const options = {
      method: method,
      uri: url,
      json: !useMultipartFormData,
      headers: {'User-Agent': `fbbizsdk-nodejs-v${Api.SDK_VERSION}`},
      body: Object,
      resolveWithFullResponse: showHeader,
    };
    // Prevent null or undefined input
    // because it can be merged with the files argument later
    if (!data) {
      data = {};
    }

    options.body = data;

    // Handle file attachments if provided
    if (useMultipartFormData || (files && Object.keys(files).length > 0)) {
      // Use formData instead of body (required by the request-promise library)
      options.formData = Object.assign(data, files);
      delete options.body;
    }

    return requestPromise(options).catch((response: Object) => {
      throw response;
    });
  }