Tell us what’s happening:
Hello guys, i am trying to access an error message in my code this is how it looks like
const status = response => {
if (response.status >= 200 && response.status < 300) {
return Promise.resolve(response)
}
return Promise.reject(new Error(response.statusText))
}
fetch('/url hast been omitted', {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify({
email: email.value,
name: name.value,
message: message.value
})
}).then(status).then(res => {
const response = res.json();// i did this so i can console.log the value, which i did
return response;
}).then( data => {
console.log('data :'+ data.errors);
}).catch(err=>{
console.log(err);
});
**
And this i my browser information when i console.log the response:
(I couldn't find arrow down so i used ♥ for arrow down. )
♥ Promise {<pending>}
__proto__: Promise
[[PromiseStatus]]: "fulfilled"
♥ [[PromiseValue]]: Object
♥ errors: Array(2)
0: {value: "", msg: "Invalid value", param: "email", location: "body"}
1: {value: "", msg: "Invalid value", param: "email", location: "body"}
length: 2
♥ __proto__: Array(0)
♥ __proto__: Object
And when i log data to the console, it looks like this:
data :[object Object],[object Object]
I don’t know how to access the errors array message. It is in this [[PromiseValue]]].
Please someone, what is wrong here, how can i access this?