简体   繁体   English

我想问一下这个错误 Unhandled Rejection (TypeError): Cannot destructure property `data` of 'undefined' or 'null'

[英]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.

相关问题 未处理的拒绝 (TypeError):无法解构“Object(...)(...)”的属性“setUser”,因为它未定义 - Unhandled Rejection (TypeError): Cannot destructure property 'setUser' of 'Object(...)(...)' as it is undefined 请问我该如何处理这个错误“未处理的拒绝(类型错误):无法读取未定义的属性'过滤器'” - Please how do i handle this error “Unhandled Rejection (Type Error): Cannot read property 'filter' of undefined” React/Redux:未处理的拒绝(TypeError):无法读取未定义的属性“数据” - React/ Redux : Unhandled Rejection (TypeError): Cannot read property 'data' of undefined 反应 - Redux | 未处理的拒绝(类型错误):无法读取未定义的属性“数据” - React - Redux | Unhandled Rejection (TypeError): Cannot read property 'data' of undefined Reactjs + Redux 未处理的拒绝(TypeError):无法读取未定义的属性“数据” - Reactjs + Redux Unhandled Rejection (TypeError): Cannot read property 'data' of undefined React-未处理的拒绝(TypeError):无法读取未定义的属性“数据” - React- Unhandled Rejection (TypeError): Cannot read property 'data' of undefined REACT JS:未处理的拒绝(TypeError):无法读取未定义的属性“数据” - REACT JS: Unhandled Rejection (TypeError): Cannot read property 'data' of undefined axios:未处理的拒绝(TypeError):无法读取未定义的属性“错误” - axios: Unhandled Rejection (TypeError): Cannot read property 'error' of undefined React - 未处理的拒绝(TypeError):无法读取未定义的属性“错误” - React - Unhandled Rejection (TypeError): Cannot read property 'error' of undefined React API错误(未处理的拒绝(TypeError):无法读取未定义的属性“ 0”) - React API Error (Unhandled Rejection (TypeError): Cannot read property '0' of undefined)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM