an unexpected error ocurred when trying to save the template
This commit is contained in:
@@ -24,7 +24,8 @@ export async function getEmailTemplate(): Promise<{ subject: string; body: strin
|
||||
return template;
|
||||
} catch (error) {
|
||||
console.error('Failed to get email template:', error);
|
||||
return null;
|
||||
// Propagate the error to be handled by the caller
|
||||
throw new Error('Database error while fetching email template.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,12 +44,16 @@ export async function updateEmailTemplate(data: { subject: string; body: string
|
||||
try {
|
||||
const stmt = db.prepare('UPDATE email_templates SET subject = ?, body = ? WHERE id = ?');
|
||||
// We assume we're updating the template with id = 1
|
||||
stmt.run(subject, body, 1);
|
||||
const info = stmt.run(subject, body, 1);
|
||||
|
||||
if (info.changes === 0) {
|
||||
return { success: false, message: 'Could not find the template to update. No changes were made.' };
|
||||
}
|
||||
|
||||
revalidatePath('/admin/settings/email-templates');
|
||||
return { success: true, message: 'Email template updated successfully!' };
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('Failed to update email template:', error);
|
||||
return { success: false, message: 'An unexpected error occurred.' };
|
||||
return { success: false, message: error.message || 'An unexpected database error occurred.' };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user