Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native error RCTJSONStringify() encountered the following error: Invalid type in JSON write (NSURL)

I am trying to use react-native-fbsdk in my react-native app. It was working fine untill yesterday. But, today it gives a weird error stating RCTJSONStringify() encountered the following error: Invalid type in JSON write (NSURL).

RN v0.42.0

Here is my code:

  _fbAuth(error, result) {
    if (error) {
      console.log("error");
      alert("login has error: " + result.error);
    } else if (result.isCancelled) {
      console.log("login cancelled");
      alert("login is cancelled.");
    } else {
      AccessToken.getCurrentAccessToken().then((data) => {
        console.log("login success");
        console.log(data.accessToken.toString());
        let accessToken = data.accessToken;
        alert(data.accessToken.toString());
        const responseInfoCallback = (error, result) => {
          if (error) {
            console.log(error);
          } else {
            console.log(result);
          }
        }

        const infoRequest = new GraphRequest(
          '/me',
          {
            accessToken: accessToken,
            parameters: {
              fields: {
                string: 'email,name,first_name,middle_name,last_name'
              }
            }
          },
          responseInfoCallback
        );

        // Start the graph request.
        new GraphRequestManager().addRequest(infoRequest).start();
      });
    }
  }

  render() {
    console.log("in new render");
    return (
      <View style={styles.container}>
      <LoginButton
        publishPermissions={["publish_actions"]}
        onLoginFinished={this._fbAuth}
        onLogoutFinished={() => alert("logout.")}/>
      </View>
    );
  }

The error information printed in debugger:

Error message

I get the above error while calling the graphAPI in the function responseInfoCallback. Any ideas what is happening ?

Update 1:

This error happens only when remote debugger is turned on!! Else it is not happening. But without remote debugger, I cannot proceed with developing the app. Are there any other methods to see log statements of react-native app other than remote debugger ?

Update 2:

The RCTJSONStringify() error happens only behind proxy. And also https fetch calls does not work under proxy. I tested in an open network, it works fine. I guess, it is to add some proxy information to RN app. I think it is related to APP transport security

like image 967
Lakshman Diwaakar Avatar asked Mar 06 '17 04:03

Lakshman Diwaakar


1 Answers

If you turn the debugger off, you can see the proper error in the XCode console. Access it from Xcode menu View/Debug Area/Activate console, if it's not enabled automatically.

like image 181
Janne Kohtamäki Avatar answered Oct 12 '22 13:10

Janne Kohtamäki