Skip to content

Commit b8762fc

Browse files
committed
fix: unpublish worker before updating DB
1 parent 49fbd69 commit b8762fc

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/domain/src/trpc/domain.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,24 +164,25 @@ export const domainRouter = router({
164164
)
165165
.mutation(async ({ input, ctx }) => {
166166
try {
167-
// Remove domain from deployment in DB first
168-
await unpublishBuild(
169-
{ projectId: input.projectId, domain: input.domain },
170-
ctx
171-
);
172-
173167
const { deploymentTrpc } = ctx.deployment;
174168

175169
// Call deployment service to delete the worker for this domain
176170
const result = await deploymentTrpc.unpublish.mutate({
177171
domain: input.domain,
178172
});
179173

180-
// Allow NOT_IMPLEMENTED to proceed (for local dev without deployment service)
174+
// If failed (and not NOT_IMPLEMENTED), return error without touching DB
181175
if (result.success === false && result.error !== "NOT_IMPLEMENTED") {
182176
return result;
183177
}
184178

179+
// Remove domain from deployment in DB after successful worker deletion
180+
// Also proceed if NOT_IMPLEMENTED (for local dev without deployment service)
181+
await unpublishBuild(
182+
{ projectId: input.projectId, domain: input.domain },
183+
ctx
184+
);
185+
185186
return { success: true } as const;
186187
} catch (error) {
187188
return createErrorResponse(error);

0 commit comments

Comments
 (0)