From 8882df4c0dd39fa4cf2e53f998359e02cba477f4 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sat, 25 Apr 2020 16:08:20 +0200 Subject: [PATCH] Improve verbosity of auth error --- src/auth/AuthGuard.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/auth/AuthGuard.ts b/src/auth/AuthGuard.ts index a808a87..778c7c4 100644 --- a/src/auth/AuthGuard.ts +++ b/src/auth/AuthGuard.ts @@ -47,7 +47,7 @@ export default abstract class AuthGuard

{ throw new Error('Unable to register user.'); } } else if (registerCallback) { - throw new AuthError('User already exists.'); + throw new UserAlreadyExistsAuthError(await proof.getEmail()); } session.auth_id = user.id; @@ -83,4 +83,13 @@ export class AuthError extends Error { constructor(message: string) { super(message); } +} + +export class UserAlreadyExistsAuthError extends AuthError { + public readonly email: string; + + constructor(userEmail: string) { + super(`User with email ${userEmail} already exists.`); + this.email = userEmail; + } } \ No newline at end of file