ofetch
ofetch copied to clipboard
.catch((err) => { console.log(err.data);}) not working
Describe the feature
const url = "http://localhost:3000/authenticate"
const payload = {
email: credentials.email,
password: credentials.password,
};
const result = await ofetch(url, {
ignoreResponseError: true,
method: "POST",
body: payload,
headers: {
"Content-Type": "application/json",
"Accept-Language": "en-US",
}
}).catch((err) => {
console.log(err.data);
})
console.log(err.data); == undefined
// log(err) return
FetchError: [POST] "http://localhost:3000/authenticate":
.catch((err) => { console.log(err.data);}) not working
Additional information
- [ ] Would you be willing to help implement this feature?
Hi, Would you be able to provide a reproduction 🙏🏻
The above command is just that. I call the authentication api using post method. I set the api server to not enabled and I can't get an error with http status code 500. I am testing to detect different errors with http status using POST method
How about use try/catch?
try {
const result = await ofetch(url, {
ignoreResponseError: true,
method: "POST",
body: payload,
headers: {
"Content-Type": "application/json",
"Accept-Language": "en-US",
}
})
} catch((err) => {
console.log(err);
})