braze-inc / braze-web-sdk

Public repo for the Braze Web SDK
https://www.braze.com
Other
70 stars 25 forks source link

[Bug]: `requestContentCardsRefresh` not always provide Error object when fail #139

Closed nitzanashi closed 1 year ago

nitzanashi commented 1 year ago

Braze Web SDK Version

4.6.3

Integration Method

NPM

Browser

Edge

Steps To Reproduce

export const refreshCards = () => {
    return new Promise((resolve, reject) => {
        braze.requestContentCardsRefresh(() => {
            resolve(braze.getCachedContentCards());
        }, reject);
    });
};

const example = () => {
    refreshCards()
        .then((cardsInfo) => {
            // Do stuff
        })
        .catch((error) => {
            if (!error) {
                error = new Error('Failed to update Braze cards');
            }

            // Report Error
        });
};

Expected Behavior

Every time requestContentCardsRefresh Fail it should provide a proper Error Object with information regarding why the method failed.

Actual Incorrect Behavior

In some occurrences the method return an empty Object when fail, we then report it to our issue tracker (Sentry) but this information does not help us to analyze and evaluate issues in the application.

This is reproducible in all Browsers

Verbose Logs

No response

Additional Information

No response

wesleyorbin commented 1 year ago

Hi @nitzanashi. This is expected behavior. As stated in our docs, we do not pass an error object to the callback. Refresh errors are most likely networking failures where it would be difficult to ascertain the exact cause. As a potential workaround, you can use the setLogger() function and report logs prepended with Braze SDK Error: to Sentry.