【发布时间】:2018-11-01 07:24:44
【问题描述】:
我在我的 react-native 应用程序中遇到了 axios 问题。 此处提供错误消息Pic1Pic2 Actions.start() 永远不会运行。
编辑 1: 这是完整的代码。 编辑2: 错误信息图片Pic3 至于结果, const res= await... 应该是问题所在。 必须添加更多细节,否则我无法更新这个问题;)
export const apiPostLogin = (
accountData
) => async dispatch => {
dispatch(setFetching(true));
try {
var instance = axios.create({
baseURL: 'https://api.xxxx.de/',
timeout: 1000
});
const res = await axios.post('/api/v1/auth/login', accountData);
Actions.Start();
dispatch(setAuthToken(res.data.token));
await dispatch(apiGetAccount(res.data.token));
console.log(res);
} catch (error) {
console.log(error.response);
dispatch(setFetching(false));
if (error.response.status === 401) {
dispatch(
setApiResponse({
apiResponse: true,
didShowResponse: false,
apiResponseError: true,
apiResponseCode: 401,
apiResponseMessage: 'E-Mail und Passwort stimmen nicht überein'
})
);
} else if (error.response.status === 417) {
dispatch(
setApiResponse({
apiResponse: true,
didShowResponse: false,
apiResponseError: true,
apiResponseCode: 417,
apiResponseMessage: 'Du hast Deine E-Mail noch nicht bestätigt'
})
);
} else {
dispatch(
setApiResponse({
apiResponse: true,
didShowResponse: false,
apiResponseError: true,
apiResponseCode: 499,
apiResponseMessage:
'Du kannst Dich im Moment nicht bei uns anmelden. Wir befinden uns im Wartungsmodus'
})
);
}
}
};
【问题讨论】:
标签: react-native react-redux axios