@@ -84,19 +84,186 @@ import { getCacheStorageInfo } from './obp/common-functions'
8484
8585 app . mount ( '#app' )
8686
87- if ( ! isDataSetup ) router . replace ( { path : 'api-server-error' } )
87+ if ( ! isDataSetup ) {
88+ // Error details are already stored in sessionStorage by setupData catch block
89+ router . replace ( { path : 'api-server-error' } )
90+ }
8891 app . config . errorHandler = ( error ) => {
89- console . log ( error )
90- router . replace ( { path : 'error' } )
92+ console . error ( '[APP ERROR]' , error )
93+ // Show error details in browser DOM
94+ const errorDiv = document . createElement ( 'div' )
95+ errorDiv . style . cssText = `
96+ position: fixed;
97+ top: 20px;
98+ left: 50%;
99+ transform: translateX(-50%);
100+ background: #f5f5f5;
101+ color: #333;
102+ padding: 20px;
103+ border-radius: 8px;
104+ max-width: 90%;
105+ max-height: 80vh;
106+ overflow: auto;
107+ z-index: 10000;
108+ font-family: monospace;
109+ white-space: pre-wrap;
110+ box-shadow: 0 4px 6px rgba(0,0,0,0.3);
111+ border: 1px solid #ddd;
112+ `
113+ let errorText = ''
114+ if ( error instanceof Error ) {
115+ errorText = `Application Error\n\nMessage:\n${ error . message } \n\nStack:\n${ error . stack || 'No stack trace available' } `
116+ errorDiv . innerHTML = `
117+ <strong style="font-size: 18px;">Application Error</strong><br><br>
118+ <strong>Message:</strong><br>${ error . message } <br><br>
119+ <strong>Stack:</strong><br>${ error . stack || 'No stack trace available' }
120+ `
121+ } else {
122+ errorText = `Application Error\n\n${ JSON . stringify ( error , null , 2 ) } `
123+ errorDiv . innerHTML = `
124+ <strong style="font-size: 18px;">Application Error</strong><br><br>
125+ ${ JSON . stringify ( error , null , 2 ) }
126+ `
127+ }
128+
129+ const copyBtn = document . createElement ( 'button' )
130+ copyBtn . textContent = '📋 Copy'
131+ copyBtn . style . cssText = `
132+ position: absolute;
133+ top: 10px;
134+ right: 90px;
135+ background: #e0e0e0;
136+ border: 1px solid #ccc;
137+ color: #333;
138+ padding: 5px 10px;
139+ cursor: pointer;
140+ border-radius: 4px;
141+ `
142+ copyBtn . onclick = async ( ) => {
143+ try {
144+ await navigator . clipboard . writeText ( errorText )
145+ copyBtn . textContent = '✓ Copied!'
146+ setTimeout ( ( ) => {
147+ copyBtn . textContent = '📋 Copy'
148+ } , 2000 )
149+ } catch ( err ) {
150+ console . error ( 'Failed to copy error:' , err )
151+ copyBtn . textContent = '✗ Failed'
152+ setTimeout ( ( ) => {
153+ copyBtn . textContent = '📋 Copy'
154+ } , 2000 )
155+ }
156+ }
157+ errorDiv . appendChild ( copyBtn )
158+
159+ const closeBtn = document . createElement ( 'button' )
160+ closeBtn . textContent = '✕ Close'
161+ closeBtn . style . cssText = `
162+ position: absolute;
163+ top: 10px;
164+ right: 10px;
165+ background: #e0e0e0;
166+ border: 1px solid #ccc;
167+ color: #333;
168+ padding: 5px 10px;
169+ cursor: pointer;
170+ border-radius: 4px;
171+ `
172+ closeBtn . onclick = ( ) => errorDiv . remove ( )
173+ errorDiv . appendChild ( closeBtn )
174+ document . body . appendChild ( errorDiv )
91175 }
92176 } catch ( error ) {
93- console . log ( error )
94- router . replace ( { path : 'error' } )
177+ console . error ( '[APP SETUP ERROR]' , error )
178+ // Show error details in browser DOM
179+ const errorDiv = document . createElement ( 'div' )
180+ errorDiv . style . cssText = `
181+ position: fixed;
182+ top: 20px;
183+ left: 50%;
184+ transform: translateX(-50%);
185+ background: #f5f5f5;
186+ color: #333;
187+ padding: 20px;
188+ border-radius: 8px;
189+ max-width: 90%;
190+ max-height: 80vh;
191+ overflow: auto;
192+ z-index: 10000;
193+ font-family: monospace;
194+ white-space: pre-wrap;
195+ box-shadow: 0 4px 6px rgba(0,0,0,0.3);
196+ border: 1px solid #ddd;
197+ `
198+ let errorText = ''
199+ if ( error instanceof Error ) {
200+ errorText = `API Explorer II Error\n\nMessage:\n${ error . message } \n\nStack:\n${ error . stack || 'No stack trace available' } `
201+ errorDiv . innerHTML = `
202+ <strong style="font-size: 18px;">API Explorer II Error</strong><br><br>
203+ <strong>Message:</strong><br>${ error . message } <br><br>
204+ <strong>Stack:</strong><br>${ error . stack || 'No stack trace available' }
205+ `
206+ } else {
207+ errorText = `API Explorer II Error\n\n${ JSON . stringify ( error , null , 2 ) } `
208+ errorDiv . innerHTML = `
209+ <strong style="font-size: 18px;">API Explorer II Error</strong><br><br>
210+ ${ JSON . stringify ( error , null , 2 ) }
211+ `
212+ }
213+
214+ const copyBtn = document . createElement ( 'button' )
215+ copyBtn . textContent = '📋 Copy'
216+ copyBtn . style . cssText = `
217+ position: absolute;
218+ top: 10px;
219+ right: 90px;
220+ background: #e0e0e0;
221+ border: 1px solid #ccc;
222+ color: #333;
223+ padding: 5px 10px;
224+ cursor: pointer;
225+ border-radius: 4px;
226+ `
227+ copyBtn . onclick = async ( ) => {
228+ try {
229+ await navigator . clipboard . writeText ( errorText )
230+ copyBtn . textContent = '✓ Copied!'
231+ setTimeout ( ( ) => {
232+ copyBtn . textContent = '📋 Copy'
233+ } , 2000 )
234+ } catch ( err ) {
235+ console . error ( 'Failed to copy error:' , err )
236+ copyBtn . textContent = '✗ Failed'
237+ setTimeout ( ( ) => {
238+ copyBtn . textContent = '📋 Copy'
239+ } , 2000 )
240+ }
241+ }
242+ errorDiv . appendChild ( copyBtn )
243+
244+ const closeBtn = document . createElement ( 'button' )
245+ closeBtn . textContent = '✕ Close'
246+ closeBtn . style . cssText = `
247+ position: absolute;
248+ top: 10px;
249+ right: 10px;
250+ background: #e0e0e0;
251+ border: 1px solid #ccc;
252+ color: #333;
253+ padding: 5px 10px;
254+ cursor: pointer;
255+ border-radius: 4px;
256+ `
257+ closeBtn . onclick = ( ) => errorDiv . remove ( )
258+ errorDiv . appendChild ( closeBtn )
259+ document . body . appendChild ( errorDiv )
95260 }
96261} ) ( )
97262
98263async function setupData ( app : App < Element > , worker : Worker ) {
99264 try {
265+ // Clear any previous error
266+ sessionStorage . removeItem ( 'setupError' )
100267 // 'open': Returns a Promise that resolves to the Cache object matching the cacheName(obp-resource-docs-cache) (a new cache is created if it doesn't already exist.)
101268 const cacheStorageOfResourceDocs = await caches . open ( 'obp-resource-docs-cache' ) // Please note: The global 'caches' read-only property returns the 'CacheStorage' object associated with the current context.
102269 // 'match': Checks if a given Request is a key in any of the Cache objects that the CacheStorage object tracks, and returns a Promise that resolves to that match.
@@ -175,6 +342,13 @@ async function setupData(app: App<Element>, worker: Worker) {
175342 return true
176343 } catch ( error ) {
177344 app . provide ( obpApiActiveVersionsKey , [ OBP_API_VERSION ] )
345+ // Store error details for display on error page
346+ const errorDetails =
347+ error instanceof Error
348+ ? { message : error . message , stack : error . stack }
349+ : { message : JSON . stringify ( error ) }
350+ sessionStorage . setItem ( 'setupError' , JSON . stringify ( errorDetails ) )
351+ console . error ( '[SETUP ERROR] Stored error details:' , errorDetails )
178352 return false
179353 }
180354}
0 commit comments