我的获取请求工作正常并返回数据,但我可能会得到未处理的承诺拒绝警告。我在请求结束时添加了catch并且catch函数确实返回了一些数据,但警告似乎没有消失。它还说参考错误,它无法找到变量错误,我不明白它所指的变量。我查看了资源,发现通常未处理的承诺拒绝是因为没有捕获或者捕获没有返回任何内容,但是我的获取请求都包含它们。
这是我的获取请求:
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
_callee$@http://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
tryCatch@http://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
invoke@http://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
tryCatch@http://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
invoke@http://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
tryCallOne@http://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
_callTimer@http://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
callImmediatesPass@http://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
callImmediates@http://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
__callImmediates@http://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
__guard@http://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
flushedQueue@http://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
flushedQueue@[native code]
callFunctionReturnFlushedQueue@http://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
callFunctionReturnFlushedQueue@[native code]
答案 0 :(得分:0)
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"
});
})
.catch(networkError => (
return(
{
status:false,
message:"Something is wrong with the server in catch",
networkError
}
)
))
开始和结束括号中可能有些起伏不定。