File tree Expand file tree Collapse file tree 4 files changed +31
-6
lines changed
components/globalErrorHandler Expand file tree Collapse file tree 4 files changed +31
-6
lines changed Original file line number Diff line number Diff line change 1
1
export * from './GlobalErrorHandler'
2
+ export * from './types'
Original file line number Diff line number Diff line change
1
+ export interface GlobalErrorMessage {
2
+ error : Error | null
3
+ params : {
4
+ colno : number
5
+ lineno : number
6
+ error : Error
7
+ event : ErrorEvent | string
8
+ source ?: string
9
+ }
10
+ }
11
+
12
+ export type GlobalErrorSubscriber = ( msg : GlobalErrorMessage ) => void
13
+ export type GlobalErrorUnsubscriber = ( ) => void
14
+
15
+ export interface GlobalErrorChannel {
16
+ subscribe : ( subscriber : GlobalErrorSubscriber ) => GlobalErrorUnsubscriber
17
+ }
Original file line number Diff line number Diff line change @@ -9,9 +9,9 @@ interface StudioErrorBoundaryProps {
9
9
children : React . ReactNode
10
10
}
11
11
12
- const errorChannel = ( globalScope as any ) . __sanityErrorChannel
12
+ const errorChannel = globalScope . __sanityErrorChannel
13
13
14
- function isKnownError ( err : unknown ) : boolean {
14
+ function isKnownError ( err : Error ) : boolean {
15
15
if ( err instanceof SchemaError ) {
16
16
return true
17
17
}
@@ -29,10 +29,15 @@ export function StudioErrorBoundary({children}: StudioErrorBoundaryProps) {
29
29
useEffect ( ( ) => {
30
30
if ( ! errorChannel ) return undefined
31
31
32
- return errorChannel . subscribe ( ( msg : any ) => {
32
+ return errorChannel . subscribe ( ( msg ) => {
33
33
// NOTE: Certain errors (such as the `ResizeObserver loop limit exceeded` error) is thrown
34
- // by the browser, and does not include an `error` property. We ignore these error.
35
- if ( ! msg . error || isKnownError ( msg . error ) ) {
34
+ // by the browser, and does not include an `error` property. We ignore these errors.
35
+ if ( ! msg . error ) {
36
+ return
37
+ }
38
+
39
+ // For errors that we "expect", eg have specific error screens for, do not push a toast
40
+ if ( isKnownError ( msg . error ) ) {
36
41
return
37
42
}
38
43
Original file line number Diff line number Diff line change
1
+ import type { GlobalErrorChannel } from '../components/globalErrorHandler'
2
+
1
3
/**
2
4
* Gets the global scope instance in a given environment.
3
5
*
7
9
* - The `self` variable is the global scope in workers and others
8
10
* - The `global` variable is the global scope in Node.js
9
11
*/
10
- function getGlobalScope ( ) {
12
+ function getGlobalScope ( ) : typeof globalThis & { __sanityErrorChannel ?: GlobalErrorChannel } {
11
13
if ( typeof globalThis !== 'undefined' ) return globalThis
12
14
if ( typeof window !== 'undefined' ) return window
13
15
if ( typeof self !== 'undefined' ) return self
You can’t perform that action at this time.
0 commit comments