Skip to content

Commit

Permalink
Handle cases where window.process is not an object (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
Finesse authored Mar 28, 2024
1 parent dca43d5 commit 791966a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/sources/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ export interface ProcessPayload {
}

export default function getProcess(): ProcessPayload {
if (window.process === undefined) {
throw new BotdError(State.Undefined, 'window.process is undefined')
const { process } = window
const errorPrefix = 'window.process is'
if (process === undefined) {
throw new BotdError(State.Undefined, `${errorPrefix} undefined`)
}
return <ProcessPayload>window.process
if (process && typeof process !== 'object') {
throw new BotdError(State.UnexpectedBehaviour, `${errorPrefix} not an object`)
}
return <ProcessPayload>process
}

0 comments on commit 791966a

Please sign in to comment.