Unverified Commit 9c993ec7 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

enhance: ignore nextjs version fetch error in dev overlay (#66271)

### What 

It's not helpful to see the network issue of fetching error on reading
nextjs version in dev overlay

### Why

Error case:

<img width="400"
src="https://github.com/vercel/next.js/assets/4800338/a7852d9b-1f98-4098-8498-a3b832efdbb0">

This should just be ignored, it's fine that the fetching is failed.
There're so many fetch errors code, it's easy to try-catch on fetch
instead of enumerate all the codes
parent 0ec02b0c
......@@ -192,14 +192,6 @@ function erroredPages(compilation: webpack.Compilation) {
return failedPages
}
const networkErrors = [
'EADDRINFO',
'ENOTFOUND',
'ETIMEDOUT',
'ECONNREFUSED',
'EAI_AGAIN',
]
export async function getVersionInfo(enabled: boolean): Promise<VersionInfo> {
let installed = '0.0.0'
......@@ -211,15 +203,21 @@ export async function getVersionInfo(enabled: boolean): Promise<VersionInfo> {
installed = require('next/package.json').version
const registry = getRegistry()
const res = await fetch(`${registry}-/package/next/dist-tags`)
let res
try {
res = await fetch(`${registry}-/package/next/dist-tags`)
} catch {
// ignore fetch errors
}
if (!res.ok) return { installed, staleness: 'unknown' }
if (!res || !res.ok) return { installed, staleness: 'unknown' }
const { latest, canary } = await res.json()
return parseVersionInfo({ installed, latest, canary })
} catch (e: any) {
if (!networkErrors.includes(e?.code)) console.error(e)
console.error(e)
return { installed, staleness: 'unknown' }
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment