Skip to content

Commit

Permalink
Fail earlier if fetch is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreif committed Nov 2, 2024
1 parent 42c616a commit 4550f14
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/ring-client-api/rest-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ async function requestWithRetry<T>(
requestOptions: RequestOptions & { url: string; allowNoResponse?: boolean },
retryCount = 0,
): Promise<T & ExtendedResponse> {
if (typeof fetch !== 'function') {
throw new Error(
`Your current NodeJS version (${process.version}) is too old to support this plugin. Please upgrade to the latest LTS version of NodeJS.`,
)
}

try {
if (requestOptions.json || requestOptions.responseType === 'json') {
requestOptions.headers = {
Expand Down Expand Up @@ -165,10 +171,6 @@ async function requestWithRetry<T>(
logError(
`There is a known issue with your current NodeJS version (${process.version}). Please see https://github.com/dgreif/ring/wiki/NGHTTP2_ENHANCE_YOUR_CALM-Error for details`,
)
} else if (e.message.includes('fetch is not defined')) {
logError(
`Your current NodeJS version (${process.version}) is too old to support this plugin. Please upgrade to the latest LTS version of NodeJS.`,
)
}
logDebug(e)
}
Expand Down

0 comments on commit 4550f14

Please sign in to comment.