Update error handling and refactor

This commit is contained in:
Salman
2024-02-10 23:00:16 +05:30
parent 5cf1ec2400
commit da377f6fda
4 changed files with 13 additions and 19 deletions
@@ -2,6 +2,7 @@ import { z } from "zod";
import { UsersSchema } from "@app/db/schemas";
import { getConfig } from "@app/lib/config/env";
import { BadRequestError } from "@app/lib/errors";
import { authRateLimit } from "@app/server/config/rateLimiter";
import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
@@ -29,7 +30,10 @@ export const registerSignupRouter = async (server: FastifyZodProvider) => {
if (config?.allowSpecificDomainSignUp) {
const domain = email.split("@")[1];
if (domain !== config.allowSpecificDomainSignUp) throw new Error(`Unsupported email domain (${domain}).`);
if (domain !== config.allowSpecificDomainSignUp)
throw new BadRequestError({
message: `User email domain (@${domain}) is not supported`
});
}
await server.services.signup.beginEmailSignupProcess(email);
return { message: `Sent an email verification code to ${email}` };