Skip to content

Commit cffb5d6

Browse files
committed
Add custom EmailError class and notification settings
Created a new EmailError class for handling email-specific errors and introduced methods to categorize these errors. Also added new columns to the User table to manage marketing and newsletter email preferences as well as an option to unsubscribe from all communications. Took 1 hour 4 minutes
1 parent 5455198 commit cffb5d6

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

lib/email/errors.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export class EmailError extends Error {
2+
constructor(
3+
message: string,
4+
public code: string,
5+
public statusCode?: number,
6+
public originalError?: unknown
7+
) {
8+
super(message)
9+
this.name = 'EmailError'
10+
}
11+
12+
static fromResendError(error: any): EmailError {
13+
if (error.name === 'validation_error') {
14+
return new EmailError(
15+
'Domain not verified. Please verify domain in Resend dashboard.',
16+
'DOMAIN_NOT_VERIFIED',
17+
error.statusCode,
18+
error
19+
)
20+
}
21+
22+
return new EmailError(
23+
error.message || 'Unknown email error',
24+
'UNKNOWN_ERROR',
25+
error.statusCode,
26+
error
27+
)
28+
}
29+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- AlterTable
2+
ALTER TABLE "User" ADD COLUMN "marketingEmails" BOOLEAN NOT NULL DEFAULT false,
3+
ADD COLUMN "newsletterEmails" BOOLEAN NOT NULL DEFAULT false,
4+
ADD COLUMN "unsubscribeFromAll" BOOLEAN NOT NULL DEFAULT false;

prisma/schema.prisma

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ model User {
163163
petitionComments PetitionComment[]
164164
petitionFollows PetitionFollow[]
165165
repMessages PetitionRepMessage[]
166+
marketingEmails Boolean @default(false)
167+
newsletterEmails Boolean @default(false)
168+
unsubscribeFromAll Boolean @default(false)
166169
}
167170

168171
// Need this to create digital twins for people that are not users

0 commit comments

Comments
 (0)