From b38a84f71f15414ac4fcebdcbd96b9e9da7af5ea Mon Sep 17 00:00:00 2001 From: xangelo Date: Fri, 27 May 2022 13:44:56 -0400 Subject: [PATCH] bugfix: don't crash on invalid session --- src/repository/accounts.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/repository/accounts.ts b/src/repository/accounts.ts index e74b81a..2ea621d 100644 --- a/src/repository/accounts.ts +++ b/src/repository/accounts.ts @@ -39,14 +39,18 @@ export class AccountRepository extends Repository { } async validate(accountId: string, token: string): Promise { - const session = await this.session.validate(accountId, token); - const account = await this.FindOne({id: session.account_id}); + try { + const session = await this.session.validate(accountId, token); + const account = await this.FindOne({id: session.account_id}); - if(!account) { - throw new NotFoundError('User not found', ERROR_CODE.USER_NOT_FOUND); - } - - return account; + if(!account) { + throw new NotFoundError('User not found', ERROR_CODE.USER_NOT_FOUND); + } + return account; + } + catch(e) { + throw new NotFoundError('User not found', ERROR_CODE.INVALID_USER_TOKEN); + } } async create(username: string, password: string) { -- 2.25.1