Use proper errors instead of string throwing
This commit is contained in:
parent
57a3ff96ea
commit
e1279ffecd
|
@ -97,3 +97,11 @@ export class InvalidAPIKeyError extends BudibaseError {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
// USERS
|
||||
|
||||
export class EmailUnavailableError extends Error {
|
||||
constructor(email: string) {
|
||||
super(`Email already taken: '${email}'`)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
ViewName,
|
||||
env as coreEnv,
|
||||
context,
|
||||
EmailUnavailableError,
|
||||
} from "@budibase/backend-core"
|
||||
import {
|
||||
AccountMetadata,
|
||||
|
@ -158,7 +159,7 @@ const validateUniqueUser = async (email: string, tenantId: string) => {
|
|||
if (env.MULTI_TENANCY) {
|
||||
const tenantUser = await getPlatformUser(email)
|
||||
if (tenantUser != null && tenantUser.tenantId !== tenantId) {
|
||||
throw `Unavailable`
|
||||
throw new EmailUnavailableError(email)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,7 +167,7 @@ const validateUniqueUser = async (email: string, tenantId: string) => {
|
|||
if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
|
||||
const account = await accounts.getAccount(email)
|
||||
if (account && account.verified && account.tenantId !== tenantId) {
|
||||
throw `Unavailable`
|
||||
throw new EmailUnavailableError(email)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -235,7 +236,7 @@ export const save = async (
|
|||
// no id was specified - load from email instead
|
||||
dbUser = await usersCore.getGlobalUserByEmail(email)
|
||||
if (dbUser && dbUser._id !== _id) {
|
||||
throw `Unavailable`
|
||||
throw new EmailUnavailableError(email)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue