我有这个函数,我在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);
})
}