{"record":{"id":"77a006b618f7f221","repo":"Dokploy/dokploy","slug":"bad-request-77a006","errorCode":"BAD_REQUEST","errorMessage":"error instanceof Error ? error.message : \"Error creating the domain\"","messagePattern":"error instanceof Error \\? error\\.message : \"Error creating the domain\"","errorType":"exception","errorClass":"TRPCError","httpStatus":400,"severity":"error","filePath":"apps/dokploy/server/api/routers/domain.ts","lineNumber":57,"sourceCode":"\t\t\t\tif (input.domainType === \"compose\" && input.composeId) {\n\t\t\t\t\tawait checkServicePermissionAndAccess(ctx, input.composeId, {\n\t\t\t\t\t\tdomain: [\"create\"],\n\t\t\t\t\t});\n\t\t\t\t} else if (input.domainType === \"application\" && input.applicationId) {\n\t\t\t\t\tawait checkServicePermissionAndAccess(ctx, input.applicationId, {\n\t\t\t\t\t\tdomain: [\"create\"],\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tconst domain = await createDomain(input);\n\t\t\t\tawait audit(ctx, {\n\t\t\t\t\taction: \"create\",\n\t\t\t\t\tresourceType: \"domain\",\n\t\t\t\t\tresourceId: domain.domainId,\n\t\t\t\t\tresourceName: domain.host,\n\t\t\t\t});\n\t\t\t\treturn domain;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: \"BAD_REQUEST\",\n\t\t\t\t\tmessage:\n\t\t\t\t\t\terror instanceof Error\n\t\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t\t: \"Error creating the domain\",\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\t\t}),\n\tbyApplicationId: protectedProcedure\n\t\t.input(apiFindOneApplication)\n\t\t.query(async ({ input, ctx }) => {\n\t\t\tawait checkServicePermissionAndAccess(ctx, input.applicationId, {\n\t\t\t\tdomain: [\"read\"],\n\t\t\t});\n\t\t\treturn await findDomainsByApplicationId(input.applicationId);\n\t\t}),\n\tbyComposeId: protectedProcedure","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/Dokploy/dokploy/blob/546686ea3587f12ec5652217dedd9f7960fb6d15/apps/dokploy/server/api/routers/domain.ts#L39-L75","documentation":"The create-domain procedure in Dokploy wraps its main body in a try/catch: any error thrown while creating a domain (unique-constraint violation, invalid host, certificate or traefik config failure) is rethrown as TRPCError BAD_REQUEST, using the original error's message when available and 'Error creating the domain' otherwise. So the message you see is a passthrough of the underlying cause; inspect error.cause for the real error.","triggerScenarios":"docker.../domain.create mutation failing downstream — most commonly creating a domain whose host already exists for the application (unique constraint), a malformed host, or missing required fields surfaced by the domain creation service.","commonSituations":"Duplicate hostnames across apps; typo'd wildcard hosts; SQLite/Postgres unique index violations from prior partial inserts; traefik/certifier config errors during domain provisioning.","solutions":["Read error.cause (or server logs) to identify the underlying failure — the TRPC message is often the DB/driver message","Check for an existing domain with the same host and remove/reuse it before creating again","Validate host format (FQDN, optional wildcard) before submitting","If a partial record was left behind, clean it up and retry"],"exampleFix":"// before\nawait trpc.domain.create.mutate({ host: 'app.example.com', ... });\n\n// after\nconst existing = (await trpc.domain.byAppId.query({ appId })).find(\n  (d) => d.host === 'app.example.com',\n);\nif (existing) throw new Error('Host already used by this app');\nawait trpc.domain.create.mutate({ host: 'app.example.com', ... });","handlingStrategy":"validation","validationCode":"const existing = (await trpc.domain.byAppId.query({ appId }))\n  .find((d) => d.host === input.host);\nif (existing) throw new Error('Host already exists for this app');","typeGuard":"const isValidHost = (h: string) =>\n  /^^(?:\\\\*\\\\.)?(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\\\.)+[a-z]{2,}$/.test(h);","tryCatchPattern":"try {\n  await trpc.domain.create.mutate(input);\n} catch (e) {\n  if (e instanceof TRPCClientError && e.data?.code === 'BAD_REQUEST') {\n    console.error('Domain create failed:', e.message, e.shape?.data?.cause);\n  }\n}","preventionTips":["Check host uniqueness per app before creating","Inspect error.cause for the real underlying failure","Validate host format client-side before submitting"],"tags":["trpc","dokploy","domain","bad-request","wrapped-error"],"backgroundTag":"unique-constraint-violation","analyzedSha":"546686ea3587f12ec5652217dedd9f7960fb6d15","analyzedAt":"2026-08-27T05:18:58.095Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}