Javascript yield工作不正常



我有这个函数,我在postman上测试过,运行良好。

export const createAccount = (password,mnemonic) => {
axios.post('http://10.0.2.2:4000/createAccount',{
password,
mnemonic
})
.then((res)=> {
console.log('--------res', res);
})
.catch((err)=>{
console.log('--------err222', err);
})

}

以下是我想如何在具有收益的生成器函数中使用它

const mnemonic = yield call(createMnemonicFromPassword, action.payload);
const seed = yield call(createAccount,action.payload,mnemonic);


const newUser = {
mnemonic,
seed,
password: action.payload,
nonce: 0,
};

yield put(setUser(newUser));

一切都很好,但当涉及到createAccount功能时,它会给我错误代码500,我不明白为什么,因为这条路由在邮递员上运行得很好,即使我只是console.log(createAccount(arg1,arg2((它也会给我正确的输出

有什么建议吗?

如果使用sagascall效果,则需要在createAccount函数中返回promise。还要确保在then:结束时返回响应

export const createAccount = (password,mnemonic) => {
return axios.post('http://10.0.2.2:4000/createAccount',{
password,
mnemonic
})
.then((res)=> {
console.log('--------res', res);
return res;
})
.catch((err)=>{
console.log('--------err222', err);
})

}

最新更新