{"record":{"id":"6f817738dfa7ceeb","repo":"Dokploy/dokploy","slug":"bad-request-6f8177","errorCode":"BAD_REQUEST","errorMessage":"Error creating the redirect","messagePattern":"Error creating the redirect","errorType":"exception","errorClass":"TRPCError","httpStatus":400,"severity":"error","filePath":"packages/server/src/services/redirect.ts","lineNumber":41,"sourceCode":"\t}\n\treturn application;\n};\n\nexport const createRedirect = async (\n\tredirectData: z.infer<typeof apiCreateRedirect>,\n) => {\n\ttry {\n\t\tawait db.transaction(async (tx) => {\n\t\t\tconst redirect = await tx\n\t\t\t\t.insert(redirects)\n\t\t\t\t.values({\n\t\t\t\t\t...redirectData,\n\t\t\t\t})\n\t\t\t\t.returning()\n\t\t\t\t.then((res) => res[0]);\n\n\t\t\tif (!redirect) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: \"BAD_REQUEST\",\n\t\t\t\t\tmessage: \"Error creating the redirect\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst application = await findApplicationById(redirect.applicationId);\n\n\t\t\tcreateRedirectMiddleware(application, redirect);\n\t\t});\n\n\t\treturn true;\n\t} catch (error) {\n\t\tthrow new TRPCError({\n\t\t\tcode: \"BAD_REQUEST\",\n\t\t\tmessage: \"Error creating this redirect\",\n\t\t\tcause: error,\n\t\t});\n\t}","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/Dokploy/dokploy/blob/546686ea3587f12ec5652217dedd9f7960fb6d15/packages/server/src/services/redirect.ts#L23-L59","documentation":"createRedirect inserts a redirect row and expects .returning() to yield the created record. If the insert returns nothing, it throws BAD_REQUEST 'Error creating the redirect' — a defensive guard after the database insert, similar in spirit to the project-create guard (error 701).","triggerScenarios":"POST createRedirect where db.insert(redirects).returning() resolves to an empty/undefined first row (DB trigger, constraint anomaly, driver behavior).","commonSituations":"Database triggers or schema drift; failed constraint surfaced silently; DB engine where .returning() behaves differently.","solutions":["Check DB logs and the redirects table schema; ensure the insert actually committed","Run pending migrations / drizzle-kit push so schema and ORM match","Retry; if persistent, insert a test row manually to isolate trigger/constraint issues"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await createRedirect(input) } catch (e) { if (e instanceof TRPCError && e.message === 'Error creating the redirect') { /* retry once; if it persists, check DB */ } }","preventionTips":["Keep migrations applied before using redirect APIs"],"tags":["trpc","drizzle","redirect","database-insert"],"backgroundTag":"database-insert-returned-no-rows","analyzedSha":"546686ea3587f12ec5652217dedd9f7960fb6d15","analyzedAt":"2026-08-27T05:18:58.095Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}