Expo fetch not working

I am currently using React Native with Expo for an application. I made a login using a Google account and I try to take some information about the user using Google’s API. I use “fetch” for this, but it doesn’t work at all, not even printing an error. I wrote a wrong link for “fetch” and still not even an error thrown. I am running the code on my devices remotely using Expo. Here is the code:

async logIn() {
  try {
    const result = await Expo.Google.logInAsync({
      androidClientId: '645999128246-gv9drk3gtad84ikeifg37p4k5phdu705.apps.googleusercontent.com',
     // iosClientId: '116235701426-lsptd400ahlctrlveoe4vlg96hcjne51.apps.googleusercontent.com',
      scopes: ['profile', 'email'],
    });

    if (result.type === 'success') {
      //console.log("AICI");
      getUserInfo(result.accessToken);
      return result.accessToken;
    } else {
      return {cancelled: true};
    }
  } catch(e) {
    return {error: true};
  }
}
getUserInfo(accessToken) {
  fetch('Wronglink', {
    headers: { Authorization: `Bearer ${accessToken}`},
  }).then(res => {console.log(res);}).catch (e => {console.log(e);});
  return;
}
  render() {
  this.logIn();   (.......)

is anything getting logged when your fetch fails?

interestingly enough I don’t believe fetch throws an error unless its a network error, so having an invalid url will actually not error out but instead return res.ok as false instead of true when the fetch is successful.

so did the res object get printed? if not I would test if your app is even reaching that code

1 Like