Skip to content

Commit a377c59

Browse files
committed
fix: error handling in the thingy mabob for websites
1 parent cb08676 commit a377c59

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

apps/dashboard/components/website-dialog.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,33 @@ export function WebsiteDialog({
103103
toast.success('Website created successfully!');
104104
}
105105
onOpenChange(false);
106-
} catch (error) {
107-
const message =
108-
error.data?.code === 'CONFLICT'
109-
? 'A website with this domain already exists.'
110-
: `Failed to ${isEditing ? 'update' : 'create'} website.`;
106+
} catch (error: any) {
107+
let message = `Failed to ${isEditing ? 'update' : 'create'} website.`;
108+
109+
if (error?.data?.code) {
110+
switch (error.data.code) {
111+
case 'CONFLICT':
112+
message = 'A website with this domain already exists.';
113+
break;
114+
case 'FORBIDDEN':
115+
message =
116+
error.message ||
117+
'You do not have permission to perform this action.';
118+
break;
119+
case 'UNAUTHORIZED':
120+
message = 'You must be logged in to perform this action.';
121+
break;
122+
case 'BAD_REQUEST':
123+
message =
124+
error.message || 'Invalid request. Please check your input.';
125+
break;
126+
default:
127+
message = error.message || message;
128+
}
129+
} else if (error?.message) {
130+
message = error.message;
131+
}
132+
111133
toast.error(message);
112134
}
113135
});

packages/rpc/src/routers/websites.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ import { nanoid } from 'nanoid';
1212
import { z } from 'zod';
1313
import { createTRPCRouter, protectedProcedure, publicProcedure } from '../trpc';
1414
import { authorizeWebsiteAccess } from '../utils/auth';
15-
import {
16-
checkAndTrackWebsiteCreation,
17-
getBillingCustomerId,
18-
trackWebsiteUsage,
19-
} from '../utils/billing';
15+
2016
import { invalidateWebsiteCaches } from '../utils/cache-invalidation';
2117

2218
const websiteCache = createDrizzleCache({ redis, namespace: 'websites' });
@@ -254,20 +250,6 @@ export const websitesRouter = createTRPCRouter({
254250
}
255251
}
256252

257-
const billingCustomerId = await getBillingCustomerId(
258-
ctx.user.id,
259-
input.organizationId
260-
);
261-
262-
const creationLimitCheck =
263-
await checkAndTrackWebsiteCreation(billingCustomerId);
264-
if (!creationLimitCheck.allowed) {
265-
throw new TRPCError({
266-
code: 'BAD_REQUEST',
267-
message: creationLimitCheck.error,
268-
});
269-
}
270-
271253
const domainToCreate = buildFullDomain(input.domain, input.subdomain);
272254
const websiteFilter = and(
273255
eq(websites.domain, domainToCreate),
@@ -391,16 +373,8 @@ export const websitesRouter = createTRPCRouter({
391373
input.id,
392374
'delete'
393375
);
394-
const billingCustomerId = await getBillingCustomerId(
395-
ctx.user.id,
396-
websiteToDelete.organizationId
397-
);
398-
399376
await ctx.db.transaction(async (tx) => {
400377
await tx.delete(websites).where(eq(websites.id, input.id));
401-
402-
// Track billing usage (decrement)
403-
await trackWebsiteUsage(billingCustomerId, -1);
404378
});
405379

406380
logger.warning(

0 commit comments

Comments
 (0)