-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): add ErrorBoundary and Suspense overlay to catch rendering …
…errors
- Loading branch information
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useRouter } from 'next/router' | ||
import { Component } from 'react' | ||
import FiveHundredPage from 'pages/500' | ||
|
||
import { getLogger } from 'utils/logging/log-util' | ||
|
||
export class ErrorBoundary extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { hasError: false } | ||
} | ||
|
||
static getDerivedStateFromError() { | ||
return { hasError: true } | ||
} | ||
|
||
componentDidCatch(error, errorInfo) { | ||
console.log(error, errorInfo) | ||
} | ||
|
||
render() { | ||
if (this.state.hasError) { | ||
return <h1>Error occur</h1> | ||
} | ||
|
||
return this.props.children | ||
} | ||
} | ||
|
||
export const SuspenseFallback = (branch) => { | ||
const { asPath } = useRouter() | ||
const logger = getLogger('Suspense Fallback') | ||
logger.error(`Error while processing ${asPath}`) | ||
|
||
return <FiveHundredPage branch={branch} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters