Error subscribing to topic: 502 - [object Object]

Hello Team,
I am integrating the push notification on message arrive in background in react native. Got some useful tutorial.


I already had firebase setup in my app so just use the subscription code from tutorial,
Push notification Extension is enabled in my Trail Account. I am getting following error:
Error subscribing to topic: 502 - [object Object]
Unable to subscribe…
Please reply how to get notifoication from comet chat and how to resolve this issue…

Thanks
Shaheen

1 Like

Hello Team,

Any update on this issue
Thanks,
Shaheen

Hello @shaheen,

Can you share screen capture of the error? Also, please confirm that the region in the subscribe api call is correct.

Hello Mayur,
The region in the subscribe api call is ‘us’. Please find below the error after i integrated code…

Please reply asap

Hello @shaheen,

It gets difficult to solve queries when you jump from one error to another. There are few question I want you to answer so that i can help you better.

Can you please let us know us what exact issue are you facing?
Are you getting this error when you call subscribe API call?
Are you running a development server with hot/live reload on?
Can you please share the code snippet?
Is the subscribe api call error subscribing to topic resolved?

Hello Mayur,

I want notifications on chat, this is the only issue in chat now. Please find below the answer to your questions:

  1. Can you please let us know us what exact issue are you facing?
    ***Chat notifications are not coming.
    ***Calls are not working in cometchat.
  2. Are you getting this error when you call subscribe API call?
    YES
  3. Are you running a development server with hot/live reload on?
    NO
  4. Can you please share the code snippet?
    Please find below the code snippet:

async cometchatLogin(UID) {
let fcmToken = await AsyncStorage.getItem(‘fcmToken’);
console.log(‘here’+fcmToken);
var appSettings = new CometChat.AppSettingsBuilder()
.subscribePresenceForAllUsers()
.setRegion(appRegion)
.build();
CometChat.init(appID, appSettings).then(
() => {
CometChat.login(UID, apiKey).then(
user => {
console.log(‘logged in’, user);
let appToken;
CometChat.getJoinedGroups().then(
groups=>{
CometChat.getAppSettings().then((settings) => {
if (settings.extensions){
settings.extensions.forEach(ext => {
if (ext.id === ‘push-notification’){
appToken = ext.appToken;
console.log(‘here’+appToken);
}
});

                var url = 'https://push-notification-us.cometchat.io/v1/subscribetomany?appToken=' + appToken;
                fetch(url, {
                  method: 'POST',
                  // eslint-disable-next-line no-undef
                  headers: new Headers({
                    'Content-Type': 'application/json',
                  }),
                  body: JSON.stringify({ appId: appID, fcmToken: fcmToken, uid: UID, groups: groups, platform: 'reactnative' }),
                })
                .then(response => {
                  if (response.status < 200 || response.status >= 400) {
                    console.log('Error subscribing to topic: ' + response.status + ' - ' + response.text());
                  } else {
                    console.log('Subscribed to all topics', response);
                  }
                })
                .catch(error => {
                  console.error(error);
                });
              }
            });
          }
        );
      }
    );
  }, error => {
    console.log('Initialization failed with error:', error);
  }
);

}

////////////////////////////////////End Of Code//////////////////////////////////
5) Is the subscribe api call error subscribing to topic resolved?
see I fiollowing some tutorial for push notification in cometchat pro, as I mentioned in th issue ticket. this ticket is raised for that issue only. Please check once and let me know is there any Trail or Paid version reason behind this issue?

Thanks,
Shaheen

Hello Team,

The issue is fixed now, I have not added Firebase server key to cometchat Pro push notification section, now added and its working. Thanks for all your support.
Please have a look for my video/audio calling issue asap.
Thanks again

Shaheen

2 Likes