[英]i wanted to ask about this error please Unhandled Rejection (TypeError): Cannot destructure property `data` of 'undefined' or 'null'
so first this I use this in authentication im using redux and each time I try to fill the email and password forms and click sign in it give me this error所以首先我在使用 redux 的身份验证中使用它,每次我尝试填写 email 和密码 forms 并单击登录它给我这个错误
Unhandled Rejection (TypeError): Cannot destructure property
data
of 'undefined' or 'null'.未处理的拒绝 (TypeError):无法解构“未定义”或“空”的属性
data
。
this is my code:这是我的代码:
import {AUTH_ATTEMPTING, AUTH_SUCCESS, AUTH_FAILED } from'./types';
import axios from 'axios';
const token_name= 'vendo_app_token';
export const login = (request_data) =>{
return async dispatch =>{
dispatch ({type: AUTH_ATTEMPTING})
try{
const {data: {token}} = await axios.post('http://localhost:5000/api/V1/login', request_data);
dispatch(success(token) );
}catch(e){
const {response: {data}} = e;
dispatch(error(data.error));
}
};
};
and this is the path I use to connect into the home page这是我用来连接到主页的路径
if(isAuth===true){
this.props.history.push('/register');
}
The only place where you are destructuring data
is in the error handler, where you are trying to destructure to ultimately get e.response.data
.您解构
data
的唯一地方是在错误处理程序中,您试图在其中解构以最终获得e.response.data
。 The error message you are getting indicates that the error that was thrown does not have a response
property.您收到的错误消息表明抛出的错误没有
response
属性。
Try:尝试:
} catch(e) {
if ( ! e.response ) {
console.error( 'Error without response:', e );
} else {
const { response : { data } } = e;
dispatch( error( data.error ) );
}
}
heyy jason well i got another error let me show you嘿,杰森,好吧,我又遇到了一个错误,让我告诉你
TypeError: Cannot read property 'push' of undefined
类型错误:无法读取未定义的属性“推送”
36 | );
37 | }
38 | if(isAuth){
> 39 | this.props.history.push('/');
| ^ 40 | }
41 | }
42 |
and this error also:这个错误也是:
12 | console.error( 'Error without response:', e );
13 | } else {
14 | const { response : { data } } = e;
> 15 | dispatch( error( data.error ) );
| ^ 16 | }
17 | }
18 |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.