'Commerce js with react native expo application throwing error
I was wondering if anyone knows why I am getting an error when trying to request information from commerce js in my react native expo application.
I made the same requests on my normal react website and everything is fine. The api key is correct but I get "Error: [TypeError: undefined is not an object (evaluating 'innerResponse.status')]" when making the request from the mobile app.
below is the full error.
[Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'innerResponse.status')]
- node_modules@chec\commerce.js\lib\index.js:1:23143 in value
- node_modules@chec\commerce.js\lib\index.js:1:24844 in promise.then._catch$argument_0
- node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
- node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:123:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:177:14 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:437:30 in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:388:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:132:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:365:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:131:4 in flushedQueue
- [native code]:null in flushedQueue
- [native code]:null in callFunctionReturnFlushedQueue
I did some more logging and found the promise was empty.
const response = commerce.categories
.list({})
.then((resp) => console.log(resp))
.catch((err) => console.log(err));
Response:
Promise {
"_U": 0,
"_V": 0,
"_W": null,
"_X": null,
}
undefined is not an object (evaluating 'innerResponse.status')
- node_modules\@chec\commerce.js\lib\index.js:1:22863 in value
- node_modules\@chec\commerce.js\lib\index.js:1:24778 in promise.then._catch$argument_0
- node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
- node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:123:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:177:14 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:437:30 in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:388:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:132:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:365:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:131:4 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in callFunctionReturnFlushedQueue
I just tested it again on the android device emulator and it works fine but on the ios device it's receiving an empty promise.
I've managed to find a workaround to my problem. Instead of using the @chec/commerce.js library I'm using apisauce and making manual requests to their api according to their docs examples. BaseUrl: "https://api.chec.io/v1".
It would be nice to know why the library doesn't work on ios though.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
