Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
fix: improve error handling
Browse files Browse the repository at this point in the history
improve error handling on edge-case that no status information has been passed
  • Loading branch information
TMUniversal committed Aug 7, 2021
1 parent 4a42459 commit d648d7e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ export default class StatusUpdater <ClientType extends DJSClient = DJSClient> {
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()
Expand Down Expand Up @@ -204,7 +209,15 @@ export default class StatusUpdater <ClientType extends DJSClient = DJSClient> {
* @returns {Promise<Presence>}
*/
public async updateStatus (activity?: ActivityOptions, shardId?: number): Promise<Presence> {
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()
Expand Down

0 comments on commit d648d7e

Please sign in to comment.