0
我的提取請求工作正常,並返回數據,但我可能獲得未處理的承諾拒絕警告。我在請求的末尾添加了catch,catch函數確實返回了一些數據,但是警告似乎沒有消失。它也說參考錯誤,它找不到變量錯誤,我不明白它指的是哪個變量。我查看了資源,發現通常未處理的承諾拒絕是因爲沒有捕獲或該捕獲不會返回任何內容,但我的提取請求包含它們兩個。可能未處理的承諾拒絕(id:0):ReferenceError:找不到變量:錯誤
這是我取的請求:
fetch(this.request)
.then(response => response.json())
.then(response => {
if(response.token === null){
return {
status:false,
message:"Incorrect login credentials",
token:response.token
}
}
return {
status:true,
message:"Login successful"
}
},
reject => ({
status:false,
message:"Something is wrong with the server in reject",
reject:reject
}))
.catch(networkError => ({
status:false,
message:"Something is wrong with the server in catch",
networkError
}))
以下是錯誤日誌:
Possible Unhandled Promise Rejection (id: 0):
ReferenceError: Can't find variable: error
[email protected]://192.168.2.102:19001/./node_modules/react-native-
scripts/build/bin/crna-entry.bundle?
platform=android&dev=true&hot=false&minify=false:87622:38
[email protected]://192.168.2.102:19001/./node_modules/react-native-
scripts/build/bin/crna-entry.bundle?
platform=android&dev=true&hot=false&minify=false:13836:44
[email protected]://192.168.2.102:19001/./node_modules/react-native-
scripts/build/bin/crna-entry.bundle?
platform=android&dev=true&hot=false&minify=false:14024:30
http://192.168.2.102:19001/./node_modules/react-native-scripts/build/bin/crna-
entry.bundle?platform=android&dev=true&hot=false&minify=false:13861:28
[email protected]://192.168.2.102:19001/./node_modules/react-native-
scripts/build/bin/crna-entry.bundle?
platform=android&dev=true&hot=false&minify=false:13836:44
[email protected]://192.168.2.102:19001/./node_modules/react-native-
scripts/build/bin/crna-entry.bundle?
platform=android&dev=true&hot=false&minify=false:13894:28
http://192.168.2.102:19001/./node_modules/react-native-scripts/build/bin/crna-
entry.bundle?platform=android&dev=true&hot=false&minify=false:13902:19
[email protected]://192.168.2.102:19001/./node_modules/react-native-
scripts/build/bin/crna-entry.bundle?
platform=android&dev=true&hot=false&minify=false:15825:14
http://192.168.2.102:19001/./node_modules/react-native-scripts/build/bin/crna-
entry.bundle?platform=android&dev=true&hot=false&minify=false:15911:25
http://192.168.2.102:19001/./node_modules/react-native-scripts/build/bin/crna-
entry.bundle?platform=android&dev=true&hot=false&minify=false:6735:24
[email protected]://192.168.2.102:19001/./node_modules/react-native-
scripts/build/bin/crna-entry.bundle?
platform=android&dev=true&hot=false&minify=false:6649:15
[email protected]://192.168.2.102:19001/./node_modules/react-native-
scripts/build/bin/crna-entry.bundle?
platform=android&dev=true&hot=false&minify=false:6877:19
[email protected]://192.168.2.102:19001/./node_modules/react-native-
scripts/build/bin/crna-entry.bundle?
platform=android&dev=true&hot=false&minify=false:6888:39
[email protected]://192.168.2.102:19001/./node_modules/react-native-
scripts/build/bin/crna-entry.bundle?
platform=android&dev=true&hot=false&minify=false:6248:30
http://192.168.2.102:19001/./node_modules/react-native-scripts/build/bin/crna-
entry.bundle?platform=android&dev=true&hot=false&minify=false:6134:32
[email protected]://192.168.2.102:19001/./node_modules/react-native-
scripts/build/bin/crna-entry.bundle?
platform=android&dev=true&hot=false&minify=false:6234:11
[email protected]://192.168.2.102:19001/./node_modules/react-native-
scripts/build/bin/crna-entry.bundle?
platform=android&dev=true&hot=false&minify=false:6133:19
[email protected][native code]
[email protected]://192.168.2.102:19001/./node_modules/react
-native-scripts/build/bin/crna-entry.bundle?
platform=android&dev=true&hot=false&minify=false:6103:31
[email protected][native code]
這仍然不起作用,你能不能給我一些關於拒絕和解決你正在調用的函數的知識。 –
我已更新答案。至於解決和拒絕,搜索'Promise' –