From 1fe34ef31d54357ff3198ae00890579c144c07b0 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 14 Nov 2022 12:41:32 +0200 Subject: [PATCH] throw errors for missing values --- src/server/components/UserDatabase.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/server/components/UserDatabase.js b/src/server/components/UserDatabase.js index b4044d4..fcaab99 100644 --- a/src/server/components/UserDatabase.js +++ b/src/server/components/UserDatabase.js @@ -32,6 +32,8 @@ class UserDatabase extends AbstractUserDatabase { } async fetchUser (id, force = false) { + + if (!id) throw new Error('Missing token'); id = id.toString(); if (!force && this.cache.has(id)) return this.cache.get(id); @@ -49,6 +51,8 @@ class UserDatabase extends AbstractUserDatabase { async fetchApplication (id, force = false) { + if (!id) throw new Error('Missing token'); + id = id.toString(); if (!force && this.cache.has(id)) return this.cache.get(id); @@ -60,9 +64,12 @@ class UserDatabase extends AbstractUserDatabase { this.cache.set(id, app); return app; - } + + } async findUser (username) { + + if (!username) throw new Error('Missing token'); let user = this.cache.find(u => u.username.toLowerCase() === username.toLowerCase()); if (user) return Promise.resolve(user); @@ -85,6 +92,7 @@ class UserDatabase extends AbstractUserDatabase { * @memberof UserDatabase */ async matchToken (token) { + if (!token) throw new Error('Missing token'); let app = this.cache.find(a => a.token.encrypted === token); @@ -100,6 +108,7 @@ class UserDatabase extends AbstractUserDatabase { user.attachApplication(app); return app; + } /**