🐛(frontend) normalize thrown values into proper Error instances

LiveKit can surface raw DOM events (for example WebSocket "error"
events, whose only enumerable key is `isTrusted`) instead of Error
instances.

When such a value ends up being captured, our error reporting logs
it as "Event: Event captured as exception with keys: isTrusted",
which is unhelpful and hides the real cause.

Add a small helper that normalizes any unknown thrown or emitted
value into a proper Error, preserving the original payload as
context.

Fixes 01997b9a-db63-7fc2-8fe4-f21dd7fd608d.
This commit is contained in:
lebaudantoine
2026-08-06 17:30:26 +02:00
committed by aleb_the_flash
parent e0ff28ed48
commit 23bb3c39d0
2 changed files with 11 additions and 1 deletions
@@ -37,6 +37,7 @@ import { notifyAutoMutedOnJoin } from '@/features/notifications/utils'
import { useSnapshot } from 'valtio'
import { userPreferencesStore } from '@/stores/userPreferences'
import { userStore } from '@/stores/user'
import { asError } from '../utils/error'
export const Conference = ({
roomId,
@@ -235,7 +236,7 @@ export const Conference = ({
backgroundColor: 'primaryDark.50 !important',
})}
onError={(e) => {
posthog.captureException(e)
posthog.captureException(asError(e))
}}
onConnected={async () => {
if (!apiConfig) return
@@ -0,0 +1,9 @@
export const asError = (value: unknown): Error => {
if (value instanceof Error) return value
if (value instanceof Event) {
return new Error(
`Unhandled event "${value.type}" from ${value.target?.constructor.name ?? 'unknown'}`
)
}
return new Error(String(value))
}