I am currently facing an issue on the fetch function when trying to make a request to my API and retrieving the results. This hasn't happened before, only started behaving like this a couple of weeks ago. This is the error I am getting.
[Unhandled promise rejection: TypeError: Network request failed]
- node_modules/whatwg-fetch/dist/fetch.umd.js:535:17 in setTimeout$argument_0
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:130:14 in _callTimer
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:383:16 in callTimers
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:416:4 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:109:6 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue
This is an example of a fetch request I am running to retrieve data from the API. Making this request on Postman does give me results and as mentioned at the start, it used to give me results before as well.
getButtons(token) {
fetch('https://**.**.org/api/v1/requests/***', {
method: 'POST',
headers: {
'token' : this.state.token,
// 'deviceCode' : this.state.device_code,
'qrvalue' : this.state.qr_value,
},
body: JSON.stringify({
'token' : this.state.token
})
}).then(response => response.json().then(data =>({
data: data,
status: response.status
})
).then(res => {
this.setState({
buttons: res.data.options
});
this.renderButtons();
}));
}
Any suggestion is welcome