Redux 返回未定义而非已解析承诺值的收益调用

Redux 返回未定义而非已解析承诺值的收益调用,redux,redux-saga,Redux,Redux Saga,我是个新手。下面是我的api调用代码- const registerUserRequest = (email, password, confirm_password, country_code, phone_number) => { fetch(URLs.baseUrl + URLs.signUpUrl(email, password, confirm_password, country_code, phone_number), { method: 'POST', head

我是个新手。下面是我的api调用代码-

const registerUserRequest = (email, password, confirm_password, country_code, phone_number) =>
{
fetch(URLs.baseUrl + URLs.signUpUrl(email, password, confirm_password, country_code, phone_number), {
    method: 'POST',
    headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
        'Cache-Control': 'no-cache, no-store, must-revalidate',
        'Pragma': 'no-cache',
        'Expires': 0
    },
})
}

function* registerUserToService(action)
{
try{
    const response = yield call(registerUserRequest, action.email, action.password, action.confirm_password, action.country_code, action.phone_number);
    const result = yield response.json();   
    if(result.error)
    {
        yield put({ type: REGISTER_USER_ERROR, error: result.error})
    }
    else
    {
        yield put({ type: REGISTER_USER_RESULT, result});
    } 
}
catch(e)
{
    console.log('registerUserException', e.message);
    yield put({ type: REGISTER_USER_ERROR, error: e.message})
}
};
但我得到的响应是未定义的,而不是已解析的承诺值,从响应中获取结果会生成异常-无法读取未定义的json值。
如果您能帮助理解这一点,我们将不胜感激。

您的函数中不返回任何内容
registerUserRequest
。如果要获得承诺,请返回
fetch

const registerUserRequest = (email, password, confirm_password, country_code, phone_number) =>
{
return fetch(URLs.baseUrl + URLs.signUpUrl(email, password, confirm_password, country_code, phone_number), {
    method: 'POST',
    headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
        'Cache-Control': 'no-cache, no-store, must-revalidate',
        'Pragma': 'no-cache',
        'Expires': 0
    },
})
}

获取不需要{}。删除周围的{}获取。像这样做

const registerUserRequest=(电子邮件、密码、确认密码、国家代码、电话号码)=>
获取(URL.baseUrl+URL.signUpUrl(电子邮件、密码、确认密码、国家代码、电话号码){
方法:“POST”,
标题:{
接受:'application/json',
“内容类型”:“应用程序/json”,
“缓存控制”:“没有缓存,没有存储,必须重新验证”,
“Pragma”:“无缓存”,
“过期”:0
},

})
请提供您的
registerUserRequest
实现。添加的“registerUserRequest”实现解析起来有点密集,但它们确实提到,
调用
效果具有不同的行为,这取决于您的函数返回的内容。在您的情况下,
registerUserRequest
没有返回承诺或生成器,因此
call
使用函数的返回值。在这种情况下,它是
未定义的