Skip to content

Commit

Permalink
feat: stop crashing the app on failed load and add applicationinsight…
Browse files Browse the repository at this point in the history
…s:load:error hook (#87)
  • Loading branch information
huang-julien authored Jul 10, 2024
1 parent e47ed8f commit 0232773
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/runtime/app/plugin.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ export default defineNuxtPlugin({

const applicationInsights = new ApplicationInsights(config)

applicationInsights.loadAppInsights()

// @ts-expect-error
delete globalThis.$fetch
globalThis.$fetch = createFetch({
defaults: {
baseURL: baseURL()
}
})
try {
applicationInsights.loadAppInsights()

// @ts-expect-error
delete globalThis.$fetch
globalThis.$fetch = createFetch({
defaults: {
baseURL: baseURL()
}
})
} catch(e) {
nuxtApp.callHook("applicationinsights:load:error", e as Error)
}
return {
provide: {
appInsights: applicationInsights
Expand Down
1 change: 1 addition & 0 deletions src/runtime/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare module 'nuxt/schema' {
declare module '#app/nuxt' {
interface RuntimeNuxtHooks {
'applicationinsights:config:client': (config: Snippet) => void
'applicationinsights:load:error': (error: Error) => void
}
}

0 comments on commit 0232773

Please sign in to comment.