fix: update email sending logic to handle disabled state and improve error handling
This commit is contained in:
parent
283eb85066
commit
779df357bc
2 changed files with 19 additions and 22 deletions
|
|
@ -57,7 +57,7 @@ const AnnuncioEdit: NextPageWithLayout<AnnuncioEditProps> = ({
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return <Status500 />;
|
return <Status500 />;
|
||||||
}
|
}
|
||||||
|
//todo avere scheda di condivizione scaricabile
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<AnnuncioEditForm data={data} />
|
<AnnuncioEditForm data={data} />
|
||||||
|
|
|
||||||
|
|
@ -203,31 +203,28 @@ export const NewMail = async ({
|
||||||
db: db,
|
db: db,
|
||||||
id: "EMAIL_OFF",
|
id: "EMAIL_OFF",
|
||||||
});
|
});
|
||||||
if (emailFlag === "true") {
|
if (emailFlag == "false") {
|
||||||
|
try {
|
||||||
|
const { html } = await genMail({ ...mail });
|
||||||
|
await mailer({
|
||||||
|
to: to,
|
||||||
|
subject: subject,
|
||||||
|
html,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
|
message: "Errore nell'invio dell'email: " + (e as Error).message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
console.warn(
|
console.warn(
|
||||||
`Email sending is disabled to:${to} subj:${subject} msgType: ${mail.mailType}`,
|
`Email sending is disabled to:${to} subj:${subject} msgType: ${mail.mailType}`,
|
||||||
);
|
);
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
message: `Email sending is disabled to:${to} subj:${subject} msgType: ${mail.mailType}`,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
const { html } = await genMail({ ...mail });
|
|
||||||
await mailer({
|
|
||||||
to: to,
|
|
||||||
subject: subject,
|
|
||||||
html,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (userId) {
|
if (userId) {
|
||||||
// Store the email in the database if userId is provided
|
// Store the email in the database if userId is provided
|
||||||
await StoreEmail({ userId, data: mail });
|
await StoreEmail({ userId, data: mail });
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
throw new TRPCError({
|
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
|
||||||
message: "Errore nell'invio dell'email: " + (e as Error).message,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue