Abhilash Cherukat
Abhilash Cherukat

Reputation: 65

Getting bodyUsed of Undefined error

I am very new to react-native and I have written code for login

payload={email:"[email protected]",password:"helo123"};
            var Options=
            {
              method: 'POST',
              headers: {'Accept': 'application/json','Content-Type': 'application/json'},
              body: payload 
            }

            fetch(Conf.API.SIGNIN, Options)
            .then((response) => 
              {
                if (response.status >= 400)
                {
                    throw new Error("Bad response from server");
                }
                return response.json();
              })
            .then((responseData) => 
            {
              //this.setState({data:responseData})
              console.log(responseData)  
            }) 
            .catch((error) => {
                  console.error("Error:"+error);
              })
            .done(); 

But Iam getting error

index.android.bundle:19291 Error:TypeError: Cannot read property 'bodyUsed' of undefined

Can any one who is expert. Can anyone help?

Upvotes: 2

Views: 1256

Answers (1)

adu
adu

Reputation: 987

Just to be explicit here, the problem was that the input URL for fetch had a value of undefined.

This can result in an exception like so:

TypeError: Cannot read property 'bodyUsed' of undefined at new Request

Make sure the first argument for fetch is defined!
Otherwise you'll have some cryptic errors to navigate.

Upvotes: 5

Related Questions