【发布时间】:2021-12-28 11:44:10
【问题描述】:
我在我的 React Native 应用程序中调用了一个函数,它抛出了如下错误:Possible Unhandled Promise Rejection (id: 44): "Request timeout"。现在我说的函数是这样的:
public async login(): Promise<any> {
try{
const manufacturer = await getManufacturer();
return this.client
.send({
command: 'handshake',
username: '',
password: '',
action: 'get',
auth_serial: this.token,
manufacturer: manufacturer,
version: this.transport?.version,
os_detail: getSystemName().concat(' ', getSystemVersion()),
})
.then(
async (result) => {
if (
result.param === 'authenticated' &&
result.auth_hash !== ''
) {
this.onLogin(result);
}
return result;
},
async (reason) => {
await this.logout();
throw reason;
},
);
}catch(err) {
console.log('Error occured',err);
}
}
我什至将它包装在 try/catch 块中。为什么它仍然抛出该错误?
【问题讨论】:
-
您正在使用
async/await语法。为所有人使用它。this.client.send(..)返回一个 Promise,等待它并将结果保存在result中。喜欢const result = await this.client.send({...});
标签: javascript reactjs react-native