Skip to content

Commit

Permalink
remove as casting and ensure we have errors to render
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesmac committed Dec 30, 2024
1 parent d05cb9b commit c526e79
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ export interface ThrownErrorBoundaryProps<T = void> {
}

export interface ThrownErrorBoundaryState<T = void> {
errorEx?: ErrorEx<T>
errorEx: ErrorEx<T> | undefined
hasError?: boolean
xyoError?: T
}

class ThrownErrorBoundaryInner<T> extends Component<ThrownErrorBoundaryProps<T>, ThrownErrorBoundaryState<T>> {
override state: ThrownErrorBoundaryState<T> = { errorEx: undefined }

static getDerivedStateFromError<T = void>(error: ErrorEx<T>) {
return { hasError: true, xyoError: ThrownErrorBoundaryInner.normalizeError<T>(error) } as ThrownErrorBoundaryState<T>
const thrownErrorBoundaryState: ThrownErrorBoundaryState<T> = {
hasError: true, errorEx: error, xyoError: ThrownErrorBoundaryInner.normalizeError<T>(error),
}
return thrownErrorBoundaryState
}

static normalizeError<T>(error: ErrorEx<T>): T {
Expand All @@ -49,9 +54,11 @@ class ThrownErrorBoundaryInner<T> extends Component<ThrownErrorBoundaryProps<T>,
const {
children, boundaryName, errorComponent, scope, title,
} = this.props

// TODO - support custom error renderer for xyoErrors
if (errorEx) {
if (errorComponent) {
return errorComponent(errorEx)
return errorComponent(errorEx, boundaryName)
}
return <ErrorRender<T> error={errorEx} errorContext={`${boundaryName} Boundary`} scope={scope} title={title} />
}
Expand Down

0 comments on commit c526e79

Please sign in to comment.