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

Bug in FacebookAdsApiBatch callbacks #67

Closed
paraboom opened this issue Jul 25, 2018 · 3 comments
Closed

Bug in FacebookAdsApiBatch callbacks #67

paraboom opened this issue Jul 25, 2018 · 3 comments
Labels

Comments

@paraboom
Copy link

paraboom commented Jul 25, 2018

Hello, guys, I started to use your library and found a pretty nasty bug in FacebookAdsApiBatch.
In the constructor we could pass successCallback as a parameter, so it'll be saved in the pool of callbacks:

constructor (
    api: FacebookAdsApi,
    successCallback?: Function,
    failureCallback?: Function
  ) {

    ...

    if (successCallback != null) {
      this._successCallbacks.push(successCallback);
    }

    if (failureCallback != null) {
      this._failureCallbacks.push(failureCallback);
    }
  }

When we're adding requests to the batch, we could pass successCallback as well, but during execution callbacks applied from the common pool of callbacks (including general success callback, which we passed in constructor):

for (let index = 0; index < responses.length; index++) {
  const response = responses[index];

  if (response != null) {
    const apiResponse = new APIResponse(response, this._batch[index]);

    // Call the success callback if provided
    if (apiResponse.isSuccess) {
      if (this._successCallbacks[index]) {
        this._successCallbacks[index](apiResponse);
      }
    } else {
      // Call the failure callback if provided
      if (this._failureCallbacks[index]) {
        this._failureCallbacks[index](apiResponse);
      }
    }
  } else {
    // Do not get response, so, we keep track of the index to retry
    retryIndices.push(index);
  }
}

So here index is an index of response, but when we add general success callback, amount of callbacks will be always response.length + 1, so last success callback will never be called.

And it seems the same situation with failureCallbacks.

@michaelwclark
Copy link
Contributor

Good catch. I'll take a crack at fixing this soon. I'd like to clean up this section of code anyways.

@stale
Copy link

stale bot commented Jan 14, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale label Jan 14, 2020
@paraboom
Copy link
Author

It seems all related code was refactored and there's no error anymore. Thanks!

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

No branches or pull requests

2 participants