drizzle + postgres + express + ts, errors

https://gist.github.com/barrybtw/67c379371c3f52a61758c94474e8ebf8 In regards to the route auth_router.post("/signup", () => ...), I get this error
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:393:5)
at ServerResponse.setHeader (node:_http_outgoing:644:11)
at ServerResponse.header (/Users/nicolaichristensen/Dev/js_world/express-caddy/node_modules/.pnpm/express@4.18.2/node_modules/express/lib/response.js:794:10)
at ServerResponse.location (/Users/nicolaichristensen/Dev/js_world/express-caddy/node_modules/.pnpm/express@4.18.2/node_modules/express/lib/response.js:915:15)
at ServerResponse.redirect (/Users/nicolaichristensen/Dev/js_world/express-caddy/node_modules/.pnpm/express@4.18.2/node_modules/express/lib/response.js:953:18)
at file:///Users/nicolaichristensen/Dev/js_world/express-caddy/src/routes/auth.mts:78:19
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_HTTP_HEADERS_SENT'
}
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:393:5)
at ServerResponse.setHeader (node:_http_outgoing:644:11)
at ServerResponse.header (/Users/nicolaichristensen/Dev/js_world/express-caddy/node_modules/.pnpm/express@4.18.2/node_modules/express/lib/response.js:794:10)
at ServerResponse.location (/Users/nicolaichristensen/Dev/js_world/express-caddy/node_modules/.pnpm/express@4.18.2/node_modules/express/lib/response.js:915:15)
at ServerResponse.redirect (/Users/nicolaichristensen/Dev/js_world/express-caddy/node_modules/.pnpm/express@4.18.2/node_modules/express/lib/response.js:953:18)
at file:///Users/nicolaichristensen/Dev/js_world/express-caddy/src/routes/auth.mts:78:19
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_HTTP_HEADERS_SENT'
}
I don't seem to be breaking that so a bit confused? And if I use a username that's already taken (username has the unique constraint) I get this error PostgresError: duplicate key value violates unique constraint "user_username_unique", and I can't import the type PostgresError as it's not exported but it's part of the types in the node modules, yet I can't import it without runtime errors. What's the standard for handling sql errors like this? SyntaxError: The requested module 'postgres' does not provide an export named 'PostgresError'
T
tzezar165d ago
@barry your error is not related to drizzle, but to express. you should return res.end | res. send | res.render etc or call next() by the way, why are you sending data in headers? they should be only used for transport of the message and should not contain the semantics of the message also the parts that involve asynchronous operations should ideally be wrapped in try-catch blocks to handle any potential errors + good practice is to split router logic from controller logic in separate files auth_route.post('/signup', signupUser)
B
barry165d ago
ahhh thx realized i needed body parser, was lazy, used headers, main focus wasnt there 🤷
Want results from more Discord servers?
Add your server
More Posts
relation select query with where conditionI want to select all user's tasks where parent id is null. Can someone help me fix this query pleasDrizzle Studio with AWS Aurora ServerlessHello All! I am having some troubles to run the Drizzle Studio Console. I am using an AWS RDS Auroreslint-plugin-drizzle add "db" as defaultIs there a reason why it is automatically applied for every delete function? I think most users woulDoes Promise.all work correct in transactions?As I just found out, pg only works with one query (or more if there is more than one connection), soFindFirst Config Optional `with`Hi, I am trying to do something like an optional findFirst config here. i am expecting the resultTypSupabase primary key typeWhen I run `introspect`, the primary key of my tables look something like this: ```id: bigint("id", Supabase/postgres get query is stuck on prod appHi, I'm coming across an issue with my discord bot, I currently have a query that checks if an usercreate exportable types for frontend servicesI feel like I'm missing something fundamental. I can create my Drizzle schema `user = mysqlTable('uno migrations for pgenums in drizzle-kitnot able to see migrations generated for pgenums in drizzle kit, is this not implemented yet or maybProperty '[IsDrizzleTable]' is missing in typeHello! I've just updated to drizzle-orm@0.29.1 and I can't use drizzle-zod anymore (@0.5.1). This Return array when parsing a schema with drizzle-valibotHello guys, I just started using drizzle-valibot and I'm not able to find in their docs nor yours hoMysql json field in where clause escaping the field namecan some one help me i am traying to create a eq(sql`${schedules.extraFields}->>'user'`, userId),, What is the best way to create conditional filters on a query?I am building an marketplace for rural real estate. I would like to build a filter system with multiCreating zod insert schema from Query with relationsI am using a Query FindFirst, with multiple relations enabled. I can infer the schema from this usin