From: xangelo Date: Fri, 27 May 2022 17:44:56 +0000 (-0400) Subject: bugfix: don't crash on invalid session X-Git-Url: https://git.xangelo.ca/?p=browser-rts.git;a=commitdiff_plain;h=b38a84f71f15414ac4fcebdcbd96b9e9da7af5ea bugfix: don't crash on invalid session --- 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) {