bugfix: don't crash on invalid session
[browser-rts.git] / src / repository / accounts.ts
index e74b81aadea4102909c563b08a08c49052377d5d..2ea621d3c3b0ff0a59987c333e09b551e8d7cde2 100644 (file)
@@ -39,14 +39,18 @@ export class AccountRepository extends Repository<Account> {
        }
 
        async validate(accountId: string, token: string): Promise<Account> {
-               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) {