Level 1
SOLVED
added this
} catch (error) {
console.log(error.response.data); // This
// Define a mapping object for validation error messages
const errorMappings = {
'The :attribute contains profanity words.': 'Your input contains profanity words.',
'The maximum age must be greater than or equal to the minimum age.': 'The maximum age must be greater than or equal to the minimum age.',
};
// Display toast with validation errors
if (error.response && error.response.status === 422) {
const validationErrors = error.response.data.errors;
let errorMessage = '';
for (const key in validationErrors) {
const errorMessageFromMap = errorMappings[validationErrors[key][0]];
if (errorMessageFromMap) {
errorMessage += `-> ${errorMessageFromMap}\n`;
} else {
errorMessage += `-> ${validationErrors[key][0]}\n`;
}
}
// Add the message from console.log(error.response.data)
errorMessage += `-> ${error.response.data.error}\n`; // and this
await showToast(errorMessage);
} else {
console.error('Error submitting form:', error);
}
}
´´´