Problem with my form
Hello, I don't understand why my Promise is not captured by my catch? I'm going to onResponseError and I'm supposed to reject the error and capture it in my catch.
try {
await useFetch('/api/mail', {
retry: false,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(submission.value),
onResponseError({ request, response, options, error }) {
Promise.reject(new ErrorEntity('Erreur', 'yolo'));
},
onResponse({ request, response, options }) {
if (response.status === 200) {
addToast({
title: 'Succès',
message: JSON.stringify(response),
type: 'success',
});
submission.value = {
firstname: '',
lastname: '',
company: '',
email: '',
phone: '',
message: '',
captcha: '',
uuidCaptcha: '',
};
}
}
});
} catch (error) {
handleError(error);
try {
await useFetch('/api/mail', {
retry: false,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(submission.value),
onResponseError({ request, response, options, error }) {
Promise.reject(new ErrorEntity('Erreur', 'yolo'));
},
onResponse({ request, response, options }) {
if (response.status === 200) {
addToast({
title: 'Succès',
message: JSON.stringify(response),
type: 'success',
});
submission.value = {
firstname: '',
lastname: '',
company: '',
email: '',
phone: '',
message: '',
captcha: '',
uuidCaptcha: '',
};
}
}
});
} catch (error) {
handleError(error);
2 Replies