1
0
mirror of synced 2026-02-05 06:00:08 -05:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Brandon Bayer
0c3fb25d44 Merge branch 'canary' into error-fallback-props 2021-01-29 20:18:40 -05:00
Brandon Bayer
e3c4bed828 add type ErrorFallbackProps for better types in _app.tsx 2021-01-29 19:45:11 -05:00
2 changed files with 15 additions and 6 deletions

View File

@@ -223,3 +223,8 @@ export declare type MutationFunction<TResult, TVariables = unknown> = (
variables: TVariables,
ctx?: any,
) => Promise<TResult>
export interface ErrorFallbackProps {
error: Error & Record<any, any>
resetErrorBoundary: (...args: Array<unknown>) => void
}

View File

@@ -1,4 +1,11 @@
import { AppProps, ErrorComponent, useRouter, AuthenticationError, AuthorizationError } from "blitz"
import {
AppProps,
ErrorComponent,
useRouter,
AuthenticationError,
AuthorizationError,
RootErrorFallback,
} from "blitz"
import { ErrorBoundary, FallbackProps } from "react-error-boundary"
import { queryCache } from "react-query"
import LoginForm from "app/auth/components/LoginForm"
@@ -22,7 +29,7 @@ export default function App({ Component, pageProps }: AppProps) {
)
}
function RootErrorFallback({ error, resetErrorBoundary }: FallbackProps) {
function RootErrorFallback({ error, resetErrorBoundary }: ErrorFallbackProps) {
if (error instanceof AuthenticationError) {
return <LoginForm onSuccess={resetErrorBoundary} />
} else if (error instanceof AuthorizationError) {
@@ -34,10 +41,7 @@ function RootErrorFallback({ error, resetErrorBoundary }: FallbackProps) {
)
} else {
return (
<ErrorComponent
statusCode={(error as any)?.statusCode || 400}
title={error?.message || error?.name}
/>
<ErrorComponent statusCode={error.statusCode || 400} title={error.message || error.name} />
)
}
}