braze-inc / braze-web-sdk

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

Question: Handling error fetching news feed #82

Closed paulogc closed 2 years ago

paulogc commented 4 years ago

Hello guys,

First ehnak you all for the awesome work, I have a question about the news feed.

In case there are errors when fetching news feed (specially server errors), I would like to handle it log it in a custom way. There is subscribeToFeedUpdates that I can use to watch for feed updates, but is this going to handle errors?

What I want to do is something like:

     AppBoy.wipeData();
     AppBoy.getUser().setLanguage(language);

     const subscriptionID = AppBoy.subscribeToFeedUpdates((feed) => {
          if (feed.error === 500) {
            log(error);
          }
      });
     AppBoy.requestFeedRefresh();
     AppBoy.removeSubscription(subscriptionID);

Thanks in advance.

wesleyorbin commented 4 years ago

Hi @paulogc! Thanks for reaching out. Unfortunately the subscribeToFeedUpdates callback is only invoked when the network call is successful. We can look into ways to improve how we expose network failures across the SDK.

Depending on your use case, you may be able to use the below workaround in the meantime. This workaround is obviously not ideal and it doesn't give you insight into why the refresh failed, but it works if you just need to log that the feed refresh was unsuccessful.

// callback is invoked on all successful calls
let callbackInvoked = false;
const subscriptionCallback = feed => {
  callbackInvoked = true;
  // other feed code
};

appboy.subscribeToFeedUpdates(subscriptionCallback);
appboy.requestFeedRefresh();
setTimeout(() => {
  if (!callbackInvoked) {
    log('Feed refresh was not successful');
  } 
  callbackInvoked = false;
}, 30000); // arbitrary timeout value; feel free to change
paulogc commented 4 years ago

Hi @wesleyorbin, thank you for your quick feedback. I believe would be good if we also have ways to access network failures as we have when there are success. The workaround may work for me now.

I Appreciate your help and support.

davidbielik commented 2 years ago

We've since added better callback handling for Content Cards (see v3.3.0 changelog). Unfortunately we will not be adding this to Newsfeed and recommend clients migrate to our newer Content Cards channel.