admin管理员组文章数量:1397142
export default class Signin extends Component {
state ={
errorMessage: null
}
here I use apisauce and credentials to test the connection
signin = async() => {
try{
const response = await api.post('/auth/authenticate')({
email:'[email protected]',
password:'123'
})
const {user, token} = response.data
await AsyncStorage.multiSet([
['@backend : token', token]
['@backend : user',JSON.stringify(user) ]
])
the expo saysthat the error is here
}catch(response){
this.setState({errorMessage: response.data.error})
}
}
render() {
return (
<View style={styles.Container}>
{ this.state.errorMessage && <Text>{ this.state.errorMessage }</Text> }
<Button onPress={this.signin} title="Entrar"/>
</View>
);
}
}
here my services/api
import { create } from 'apisauce'
const api = create({
baseURL: 'http://locahost:300'
})
api.addResponseTransform(response => {
if (!response.ok) throw response;
console.log(response)
})
export default api;
export default class Signin extends Component {
state ={
errorMessage: null
}
here I use apisauce and credentials to test the connection
signin = async() => {
try{
const response = await api.post('/auth/authenticate')({
email:'[email protected]',
password:'123'
})
const {user, token} = response.data
await AsyncStorage.multiSet([
['@backend : token', token]
['@backend : user',JSON.stringify(user) ]
])
the expo saysthat the error is here
}catch(response){
this.setState({errorMessage: response.data.error})
}
}
render() {
return (
<View style={styles.Container}>
{ this.state.errorMessage && <Text>{ this.state.errorMessage }</Text> }
<Button onPress={this.signin} title="Entrar"/>
</View>
);
}
}
here my services/api
import { create } from 'apisauce'
const api = create({
baseURL: 'http://locahost:300'
})
api.addResponseTransform(response => {
if (!response.ok) throw response;
console.log(response)
})
export default api;
Share
Improve this question
edited Jan 8, 2021 at 22:33
Dharman♦
33.4k27 gold badges101 silver badges147 bronze badges
asked Jan 8, 2021 at 22:08
Paulo AvilaPaulo Avila
3211 gold badge3 silver badges15 bronze badges
1 Answer
Reset to default 3TypeError: undefined is not an object
This error usually indicates that you're trying to access a property of a non-object type. The value exposed in the catch
block will be an Error
object, which does not have a data
property.
Change your catch
block to the following.
} catch (error) {
this.setState({errorMessage: error.message})
}
本文标签:
版权声明:本文标题:javascript - Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_context.t0.data.error& 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744126422a2591973.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论