Skip to content

Beautiful Open-Source Form Builder

Enhance Sentry Client Configuration for Improved Error Handling

JhumanJ29b513a6f64e
diff --git a/client/plugins/0.error-handler.client.js b/client/plugins/0.error-handler.client.js
new file mode 100644
index 000000000..29025e510
--- /dev/null
+++ b/client/plugins/0.error-handler.client.js
@@ -0,0 +1,21 @@
+export default defineNuxtPlugin((nuxtApp) => {
+const router = useRouter()
+
+ router.onError((error) => {
+ if (
+ error.message.includes('Failed to fetch dynamically imported module') ||
+ error.message.includes('Failed to load resource')
+ ) {
+ window.location.reload()
+ }
+ })
+
+ nuxtApp.hook('app:error', (error) => {
+ if (
+ error.message.includes('Loading chunk') ||
+ error.message.includes('Failed to load resource')
+ ) {
+ window.location.reload()
+ }
+ })
+})
\ No newline at end of file
diff --git a/client/sentry.client.config.ts b/client/sentry.client.config.ts
index 150cce0b1..4ace92179 100644
--- a/client/sentry.client.config.ts
+++ b/client/sentry.client.config.ts
@@ -24,23 +24,37 @@ Sentry.init({
beforeSend (event) {
if (event.exception?.values?.length) {
+ const errorType = event.exception.values[0]?.type || '';
+ const errorValue = event.exception.values[0]?.value || '';
+
// Don't send validation exceptions to Sentry
if (
- event.exception.values[0]?.type === 'FetchError'
- && (event.exception.values[0]?.value?.includes('422')
- || event.exception.values[0]?.value?.includes('401'))
- )
+ errorType === 'FetchError' &&
+ (errorValue.includes('422') || errorValue.includes('401'))
+ ) {
return null
+ }
+
+ // Filter out chunk loading errors
+ if (
+ errorValue.includes('Failed to fetch dynamically imported module') ||
+ errorValue.includes('Loading chunk') ||
+ errorValue.includes('Failed to load resource')
+ ) {
+ return null
+ }
}
+
const authStore = useAuthStore()
if (authStore.check) {
+ const user = authStore.user as { id?: string; email?: string } | null
Sentry.setUser({
- id: authStore.user?.id,
- email: authStore.user?.email
+ id: user?.id,
+ email: user?.email
})
event.user = {
- id: authStore.user?.id,
- email: authStore.user?.email
+ id: user?.id,
+ email: user?.email
}
}
return event