facebook / facebook-nodejs-business-sdk

Node.js SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
497 stars 227 forks source link

17.0.3 introduces error: "TypeError: Cannot read properties of undefined (reading 'map')" #260

Closed sgtdck closed 1 year ago

sgtdck commented 1 year ago

Which SDK version are you using?

17.0.3

What's the issue?

When calling endpoints which use response.data property, the buildObjectsFromResponse method tries to map these data items. However, since 17.0.3, it dies horribly, as it seems the response param is now actually response.data, thus it tries to perform response.data.data.map(...) - and no such property exists.

It seems that the changes in this commit are the culprit.

I have confirmed that downgrading to 17.0.2 fixes the problem immediately.

CC @stcheng as I believe it's your commit

Steps/Sample code to reproduce the issue

FacebookAdsApi.init(user.accessToken);
const fbUser = new User(user.userID);
const adAccounts = await fbUser.getAdAccounts(['name']);
console.log('result', adAccounts); // promise will reject, error thrown in console

Observed Results:

"TypeError: Cannot read properties of undefined (reading 'map')
    at Cursor._this._buildObjectsFromResponse (https://localhost:1234/index.7ba870ae.js:70042:34)
    at https://localhost:1234/index.7ba870ae.js:70031:41"

Expected Results:

a neat list of AdAccounts

Workaround

Use 17.0.2 in the meantime.

stcheng commented 1 year ago

checking

stcheng commented 1 year ago

@sgtdck I cannot reproduce this issue actually. Internally we have tests covering the cursor and paging scenario. When you did version bump, did you run a clean npm install?

stcheng commented 1 year ago

@genlyken could you check if you encountered this issue?

genlyken commented 1 year ago

I couldn't reproduce it either. I checked the cjs.js to make sure, and i'm using axios there.

sgtdck commented 1 year ago

It appears to have been a (persistent!) glitch in the matrix. After trying to reproduce once more, the bug has vanished.

Sorry for wasting your time, everyone - and thank you for looking into it so prompty. 👍