drizzle + postgres + express + ts, errors
https://gist.github.com/barrybtw/67c379371c3f52a61758c94474e8ebf8
In regards to the route
auth_router.post("/signup", () => ...)
, I get this error
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'
2 Replies
@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)
ahhh thx
realized i needed body parser, was lazy, used headers, main focus wasnt there 🤷