Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

add NON_RETRIABLE_ERROR_CODES

Kiran Kc9773db4dad1
diff --git a/apps/web/lib/api/utils/with-prisma-retry.ts b/apps/web/lib/api/utils/with-prisma-retry.ts
index 3608ebc692..7b4877a720 100644
--- a/apps/web/lib/api/utils/with-prisma-retry.ts
+++ b/apps/web/lib/api/utils/with-prisma-retry.ts
@@ -6,6 +6,14 @@ const DEFAULT_CONFIG = {
exponentialBackoff: true,
};
+const NON_RETRIABLE_ERROR_CODES = new Set([
+ "P2000", // Value too long for column
+ "P2001", // Record not found for where condition
+ "P2002", // Unique constraint violation
+ "P2003", // Foreign key constraint violation
+ "P2025", // Record not found for operation
+]);
+
// Helper function for retrying operations
export async function withPrismaRetry<T>(
operation: () => Promise<T>,
@@ -19,9 +27,11 @@ export async function withPrismaRetry<T>(
} catch (error) {
lastError = error as Error;
- // Don't retry unique constraint violations, FK violations, or not-found
if (error instanceof Prisma.PrismaClientKnownRequestError) {
- throw error;
+ // Only exclude permanent errors, not connection issues
+ if (NON_RETRIABLE_ERROR_CODES.has(error.code)) {
+ throw error;
+ }
}
// Also avoid retrying on validation errors