Skip to content

Commit

Permalink
fixed error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rosewang01 committed May 17, 2024
1 parent 04b4d5f commit 323c18d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server/src/controllers/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const inviteUser = async (

function validateEmail(email: string) {
if (!email.match(emailRegex)) {
throw new Error('Invalid email');
next(ApiError.badRequest(`Invalid email: ${email}`));
}
}

Expand All @@ -171,7 +171,7 @@ const inviteUser = async (
await createInvite(email, verificationToken);
}
} catch (err: any) {
throw new Error('Error creating invite');
next(ApiError.internal(`Error creating invite: ${err.message}`));
}
}

Expand All @@ -183,7 +183,7 @@ const inviteUser = async (
emailInviteLink(email, verificationToken);
return;
} catch (err: any) {
throw new Error('Error sending invite');
next(ApiError.internal(`Error sending invite: ${err.message}`));
}
}

Expand Down Expand Up @@ -212,7 +212,7 @@ const inviteUser = async (

const emailInviteList = lowercaseEmailList.filter((email) => {
if (existingUserEmails.includes(email)) {
throw new Error(`An account with email ${email} already exists.`);
next(ApiError.badRequest(`User with email ${email} already exists`));
}
return !existingUserEmails.includes(email);
});
Expand Down

0 comments on commit 323c18d

Please sign in to comment.