From ae049c8da270735c741b7259bdd44db15b4507d8 Mon Sep 17 00:00:00 2001 From: dskvr Date: Tue, 28 Nov 2023 19:42:07 +0100 Subject: [PATCH] no empty array as argument on check() --- packages/nocap/src/classes/Base.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nocap/src/classes/Base.js b/packages/nocap/src/classes/Base.js index ef068b9a..5e589548 100644 --- a/packages/nocap/src/classes/Base.js +++ b/packages/nocap/src/classes/Base.js @@ -77,17 +77,18 @@ export default class { await this.check(this.checks) return this.results.dump() } - + if(typeof keys === 'string') return this._check(keys) - if(keys instanceof Array) { + if(keys instanceof Array && keys.length) { let result = {} for(const key of keys){ result = { ...result, ...await this._check(key) } } return new Promise(resolve => resolve(result)) } + return this.throw(`check(${keys}) failed. keys must be string or populated array`) } async _check(key){ @@ -108,6 +109,7 @@ export default class { if( typeof key !== 'string') throw new Error('Key must be string') + if( !this?.adapters?.[adapter]?.[`check_${key}`] ) throw new Error(`check_${key} method not found in ${adapter} Adapter, key should be 'connect', 'read', or 'write'`)