Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for response forever in Cloud Functions #469

Open
JackDaexter opened this issue Aug 25, 2023 · 0 comments
Open

Wait for response forever in Cloud Functions #469

JackDaexter opened this issue Aug 25, 2023 · 0 comments

Comments

@JackDaexter
Copy link

Hello, i have a very sstrange problem.
The library works very well on local, but when i use it in my cloud functions, i have an error that says the Promise took too much time. The promise await forever.

Thats my code

import * as functions from "firebase-functions";
import { errors, GoogleAdsApi } from "google-ads-api";
import { GoogleAdsProductResponse } from "../../interfaces/googleAdsInterfaces";
import { getUserRefreshToken } from "../../src/userTokenManager";

const client = new GoogleAdsApi({
  client_id: process.env.VITE_APP_CLIENT_ID!,
  client_secret: process.env.VITE_APP_CLIENT_SECRET!,
  developer_token: process.env.VITE_GOOGLEADS_DEV_TOKEN!,
});

export async function getProductsAdsInformation(
  userUid: string,
  customerId: string
): Promise<GoogleAdsProductResponse[] | null> {
  const refreshToken = await getUserRefreshToken(userUid);
  const customer = client.Customer({
    customer_id: customerId,
    refresh_token: refreshToken,
  });

  functions.logger.warn(`getProductsAdsInformation`);
  let requestResponse: any = null;

  try {
    requestResponse = await customer
      .query(
        `SELECT 
  customer.id, 
  metrics.clicks, 
  metrics.conversions, 
  metrics.conversions_value, 
  metrics.conversions_from_interactions_rate, 
  metrics.impressions,
  metrics.cost_micros,
  metrics.ctr, 
 
FROM shopping_performance_view `
      )
     
  } catch (err) {
    if (err instanceof errors.GoogleAdsFailure) {
      console.log(err.errors); // Array of errors.GoogleAdsError instances

      // Get the first one and explicitly check for a certain errors type
      const [firstError] = err.errors;
      if (
        firstError.error_code ===
        errors.QueryErrorEnum.QueryError.UNRECOGNIZED_FIELD
      ) {
        console.log(
          `Error: using invalid field "${firstError.trigger}" in query`
        );
      }
    } else {
      functions.logger.error(`type is ${typeof err}`);
    }
    console.error("ERROR");
  }

  return requestResponse;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant