11// DO NOT IMPORT window.config HERE!
22// to make sure the error handler always works, we should never import `window.config`, because
33// some user's custom template breaks it.
4+ import type { Intent } from './types.ts' ;
45
56// This sets up the URL prefix used in webpack's chunk loading.
67// This file must be imported before any lazy-loading is being attempted.
78__webpack_public_path__ = `${ window . config ?. assetUrlPrefix ?? '/assets' } /` ;
89
9- function shouldIgnoreError ( err ) {
10+ function shouldIgnoreError ( err : Error ) {
1011 const ignorePatterns = [
1112 '/assets/js/monaco.' , // https://github.com/go-gitea/gitea/issues/30861 , https://github.com/microsoft/monaco-editor/issues/4496
1213 ] ;
@@ -16,14 +17,14 @@ function shouldIgnoreError(err) {
1617 return false ;
1718}
1819
19- export function showGlobalErrorMessage ( msg , msgType = 'error' ) {
20+ export function showGlobalErrorMessage ( msg : string , msgType : Intent = 'error' ) {
2021 const msgContainer = document . querySelector ( '.page-content' ) ?? document . body ;
2122 const msgCompact = msg . replace ( / \W / g, '' ) . trim ( ) ; // compact the message to a data attribute to avoid too many duplicated messages
22- let msgDiv = msgContainer . querySelector ( `.js-global-error[data-global-error-msg-compact="${ msgCompact } "]` ) ;
23+ let msgDiv = msgContainer . querySelector < HTMLDivElement > ( `.js-global-error[data-global-error-msg-compact="${ msgCompact } "]` ) ;
2324 if ( ! msgDiv ) {
2425 const el = document . createElement ( 'div' ) ;
2526 el . innerHTML = `<div class="ui container js-global-error tw-my-[--page-spacing]"><div class="ui ${ msgType } message tw-text-center tw-whitespace-pre-line"></div></div>` ;
26- msgDiv = el . childNodes [ 0 ] ;
27+ msgDiv = el . childNodes [ 0 ] as HTMLDivElement ;
2728 }
2829 // merge duplicated messages into "the message (count)" format
2930 const msgCount = Number ( msgDiv . getAttribute ( `data-global-error-msg-count` ) ) + 1 ;
@@ -33,18 +34,7 @@ export function showGlobalErrorMessage(msg, msgType = 'error') {
3334 msgContainer . prepend ( msgDiv ) ;
3435}
3536
36- /**
37- * @param {ErrorEvent|PromiseRejectionEvent } event - Event
38- * @param {string } event.message - Only present on ErrorEvent
39- * @param {string } event.error - Only present on ErrorEvent
40- * @param {string } event.type - Only present on ErrorEvent
41- * @param {string } event.filename - Only present on ErrorEvent
42- * @param {number } event.lineno - Only present on ErrorEvent
43- * @param {number } event.colno - Only present on ErrorEvent
44- * @param {string } event.reason - Only present on PromiseRejectionEvent
45- * @param {number } event.promise - Only present on PromiseRejectionEvent
46- */
47- function processWindowErrorEvent ( { error, reason, message, type, filename, lineno, colno} ) {
37+ function processWindowErrorEvent ( { error, reason, message, type, filename, lineno, colno} : ErrorEvent & PromiseRejectionEvent ) {
4838 const err = error ?? reason ;
4939 const assetBaseUrl = String ( new URL ( __webpack_public_path__ , window . location . origin ) ) ;
5040 const { runModeIsProd} = window . config ?? { } ;
@@ -90,7 +80,8 @@ function initGlobalErrorHandler() {
9080 }
9181 // then, change _globalHandlerErrors to an object with push method, to process further error
9282 // events directly
93- window . _globalHandlerErrors = { _inited : true , push : ( e ) => processWindowErrorEvent ( e ) } ;
83+ // @ts -expect-error -- this should be refactored to not use a fake array
84+ window . _globalHandlerErrors = { _inited : true , push : ( e : ErrorEvent & PromiseRejectionEvent ) => processWindowErrorEvent ( e ) } ;
9485}
9586
9687initGlobalErrorHandler ( ) ;
0 commit comments