throw errors for missing values

This commit is contained in:
Erik 2022-11-14 12:41:32 +02:00
parent 9779fb7e9d
commit 1fe34ef31d
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -33,6 +33,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);
if (id.includes('temp')) return null;
@ -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,10 +64,13 @@ 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;
}
/**