Dokploy/dokploy · error · TRPCError

BAD_REQUEST

BAD_REQUEST

Error message

Error creating the redirect

What it means

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).

Source

Thrown at packages/server/src/services/redirect.ts:41

	}
	return application;
};

export const createRedirect = async (
	redirectData: z.infer<typeof apiCreateRedirect>,
) => {
	try {
		await db.transaction(async (tx) => {
			const redirect = await tx
				.insert(redirects)
				.values({
					...redirectData,
				})
				.returning()
				.then((res) => res[0]);

			if (!redirect) {
				throw new TRPCError({
					code: "BAD_REQUEST",
					message: "Error creating the redirect",
				});
			}

			const application = await findApplicationById(redirect.applicationId);

			createRedirectMiddleware(application, redirect);
		});

		return true;
	} catch (error) {
		throw new TRPCError({
			code: "BAD_REQUEST",
			message: "Error creating this redirect",
			cause: error,
		});
	}

View on GitHub (pinned to 546686ea35)

Solutions

  1. Check DB logs and the redirects table schema; ensure the insert actually committed
  2. Run pending migrations / drizzle-kit push so schema and ORM match
  3. Retry; if persistent, insert a test row manually to isolate trigger/constraint issues
Defensive patterns

Strategy: try-catch

Try / catch

try { await createRedirect(input) } catch (e) { if (e instanceof TRPCError && e.message === 'Error creating the redirect') { /* retry once; if it persists, check DB */ } }

Prevention

When it happens

Trigger: POST createRedirect where db.insert(redirects).returning() resolves to an empty/undefined first row (DB trigger, constraint anomaly, driver behavior).

Common situations: Database triggers or schema drift; failed constraint surfaced silently; DB engine where .returning() behaves differently.

Understand the failure class

Background: BAD_REQUEST error code: request rejected as invalid (HTTP 400) - causes and fixes across libraries — this error's family across 8 libraries.

Related errors


AI-assisted analysis of Dokploy/dokploy@546686ea35 (2026-08-27). Data as JSON: /api/errors/6f817738dfa7ceeb. Report an issue: GitHub.