signUp: publicProcedure
.input(signUpSchema)
.use(async ({ctx, next})=>{
const res = await next();
// does not work since the instance of res.error is no longer PostgresError but TRPCError
if(!res.ok && isPgError(res.error) && res.error.constraint_name === "user_email_unique") {
throw new TRPCError({
code: "CONFLICT",
message: "this email is already used",
});
}
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: res.error instanceof Error ? res.error.message : "unhandled error",
});
})
.mutation(async ({ ctx, input }) => {
// ...
// could throw on duplicate email.
await ctx.db.insert(userTable).values(...);
// ...
}),
signUp: publicProcedure
.input(signUpSchema)
.use(async ({ctx, next})=>{
const res = await next();
// does not work since the instance of res.error is no longer PostgresError but TRPCError
if(!res.ok && isPgError(res.error) && res.error.constraint_name === "user_email_unique") {
throw new TRPCError({
code: "CONFLICT",
message: "this email is already used",
});
}
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: res.error instanceof Error ? res.error.message : "unhandled error",
});
})
.mutation(async ({ ctx, input }) => {
// ...
// could throw on duplicate email.
await ctx.db.insert(userTable).values(...);
// ...
}),