Skip to content

Commit

Permalink
feat(studio): add CorsOriginErrorScreen to StudioErrorBoundary
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanwikner committed Aug 10, 2022
1 parent e1b976d commit 2b950e1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/sanity/src/studio/StudioErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {Button, Card, Code, ErrorBoundary, Heading, Stack, useToast} from '@sani
import {SchemaError} from '../config'
import {isRecord} from '../util'
import {globalScope} from '../util/globalScope'
import {SchemaErrorsScreen} from './screens'
import {CorsOriginError} from '../datastores'
import {CorsOriginErrorScreen, SchemaErrorsScreen} from './screens'

interface StudioErrorBoundaryProps {
children: React.ReactNode
Expand All @@ -16,6 +17,10 @@ function isKnownError(err: Error): boolean {
return true
}

if (err instanceof CorsOriginError) {
return true
}

return false
}

Expand All @@ -42,6 +47,7 @@ export function StudioErrorBoundary({children}: StudioErrorBoundaryProps) {
}

console.error(msg.error)

pushToast({
closable: true,
description: msg.error.message,
Expand All @@ -52,6 +58,10 @@ export function StudioErrorBoundary({children}: StudioErrorBoundaryProps) {
})
}, [pushToast])

if (error instanceof CorsOriginError) {
return <CorsOriginErrorScreen projectId={error?.projectId} />
}

if (error instanceof SchemaError) {
return <SchemaErrorsScreen schema={error.schema} />
}
Expand Down

0 comments on commit 2b950e1

Please sign in to comment.