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) {
|
||||
return <Status500 />;
|
||||
}
|
||||
|
||||
//todo avere scheda di condivizione scaricabile
|
||||
return (
|
||||
<>
|
||||
<AnnuncioEditForm data={data} />
|
||||
|
|
|
|||
|
|
@ -203,31 +203,28 @@ export const NewMail = async ({
|
|||
db: db,
|
||||
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(
|
||||
`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) {
|
||||
// Store the email in the database if userId is provided
|
||||
await StoreEmail({ userId, data: mail });
|
||||
}
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
message: "Errore nell'invio dell'email: " + (e as Error).message,
|
||||
});
|
||||
if (userId) {
|
||||
// Store the email in the database if userId is provided
|
||||
await StoreEmail({ userId, data: mail });
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue