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

Retrieving subscriptions fails with message: Error fetching subscriptions: TypeError: e.json is not a function #441

Closed
andreban opened this issue Sep 20, 2017 · 0 comments
Labels

Comments

@andreban
Copy link
Member

andreban commented Sep 20, 2017

This seems to happen when a user hasn't authorised notifications and doesn't have a token yet. The promise chain seems to be broken. Something like the below will fix it.

getSubscriptions() {
    const messaging = firebase.messaging();
    return messaging.getToken()
      .then(token => {
        if (!token) {
          return Promise.resolve([]);
        }
        const url = TOPICS_ENDPOINT + '?token=' + token;
        return fetch(url, { headers: { Accept: 'application/json' }})
          .then(response => {
            return response.json();
          })
          .then(json => {
            return json.subscriptions;
          })
          .catch(err => {
            console.error('Error fetching subscriptions: ', err);
            return Promise.resolve([]);
          });;
      });
  }
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

1 participant