From d648d7e6cb9694c0568d3a7a9c9d160e64222d81 Mon Sep 17 00:00:00 2001 From: Universal Studio Date: Sat, 7 Aug 2021 07:57:55 +0200 Subject: [PATCH] fix: improve error handling improve error handling on edge-case that no status information has been passed --- src/index.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index dd14277..2d21b2c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -94,6 +94,11 @@ export default class StatusUpdater { if (this.timer !== false) { throw new Error('automatic status updates are already enabled') } + + if (!this.statuses || this.statuses.length === 0) { + throw new Error('must have at least one status to choose from') + } + this.timer = setInterval( () => { this.updateStatus() @@ -204,7 +209,15 @@ export default class StatusUpdater { * @returns {Promise} */ public async updateStatus (activity?: ActivityOptions, shardId?: number): Promise { - if (!this.client.user) throw new Error('cannot update status of undefined client user') + if (!this.client.user) { + throw new Error('cannot update status of undefined client user') + } + + if (!this.statuses || this.statuses.length === 0) { + throw new Error('must have at least one status to choose from') + } + + // get current information about guild amounts etc. from client, feed it to parser this._updateParserData() const $activity = activity ? this._getSafeActivity(activity) : this._chooseActivity()