Sean Hayes
04/23/2022, 9:34 PMnotifyOff
as true
correctly prevents the import without notifying via email as an Unhandled Error, but the CSV File contains the entire stringified ERROR Object.
This is ugly and initially confusing for users.
I can throw the message without creating the error Object, but this will trigger the email notification, and we can’t have that, since these are validation errors, which users will definitely encounter, and we don’t want to blow up our inboxes with false-positives…
Has anyone accomplished this differently with a better result?Sean Hayes
04/23/2022, 11:40 PMSean Hayes
04/23/2022, 11:49 PMthrow createCSVUserError({
name: 'CSV_VALIDATION_ERROR',
message: 'You can only use XXX Account for this transaction!',
notifyOff: true
});
/**
* Create an Error Object which prints only the Error Message when toString() is called.
* @param {Object} errorOptions
* @return {Object} error
*/
function createCSVUserError(errorOptions) {
const csvUserError = error.create(errorOptions);
if (errorOptions.notifyOff) {
// log the original error
log.error({title: 'Returning CSV User Error', details: csvUserError});
}
// print only the error message to the csv error line.
csvUserError.toString = () => {
return csvUserError.message;
};
return csvUserError;
}