File tree Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ export function setupAppVersionNotification() {
2525
2626 const buildTime = await getHtmlBuildTime ( ) ;
2727
28- // If build time hasn't changed, no update is needed
29- if ( buildTime === BUILD_TIME ) {
28+ // If failed to get build time or build time hasn't changed, no update is needed.
29+ if ( ! buildTime || buildTime === BUILD_TIME ) {
3030 return ;
3131 }
3232
@@ -88,16 +88,22 @@ export function setupAppVersionNotification() {
8888 }
8989}
9090
91- async function getHtmlBuildTime ( ) {
91+ async function getHtmlBuildTime ( ) : Promise < string | null > {
9292 const baseUrl = import . meta. env . VITE_BASE_URL || '/' ;
9393
94- const res = await fetch ( `${ baseUrl } index.html?time=${ Date . now ( ) } ` ) ;
94+ try {
95+ const res = await fetch ( `${ baseUrl } index.html?time=${ Date . now ( ) } ` ) ;
9596
96- const html = await res . text ( ) ;
97-
98- const match = html . match ( / < m e t a n a m e = " b u i l d T i m e " c o n t e n t = " ( .* ) " > / ) ;
99-
100- const buildTime = match ?. [ 1 ] || '' ;
97+ if ( ! res . ok ) {
98+ console . error ( 'getHtmlBuildTime error:' , res . status , res . statusText ) ;
99+ return null ;
100+ }
101101
102- return buildTime ;
102+ const html = await res . text ( ) ;
103+ const match = html . match ( / < m e t a n a m e = " b u i l d T i m e " c o n t e n t = " ( .* ) " > / ) ;
104+ return match ?. [ 1 ] || null ;
105+ } catch ( error ) {
106+ console . error ( 'getHtmlBuildTime error:' , error ) ;
107+ return null ;
108+ }
103109}
You can’t perform that action at this time.
0 commit comments