-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: add error boundaries, improve error handling #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
53338ca
refactor: add and use error boundaries
robsimmons 0ad14d9
additional abstractions and error handling
robsimmons 18868c1
55acb29
move dev signup to server, have dev button automatically sign in
robsimmons bad5f09
Update src/app/[userName]/actions.ts
robsimmons 7379f49
Update src/app/[userName]/actions.ts
robsimmons c08194b
Update src/app/error.tsx
robsimmons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,53 @@ | ||
| 'use client' | ||
|
|
||
| import { useEffect } from 'react' | ||
| import { useSWRConfig } from 'swr' | ||
|
|
||
| import ErrorBox from './components/ErrorBox' | ||
|
|
||
| interface ErrorBoundaryProps { | ||
| error: Error & { digest?: string } | ||
| retry: () => void | ||
| } | ||
|
|
||
| /** | ||
| * App-level error boundary | ||
| * https://nextjs.org/docs/app/api-reference/file-conventions/error | ||
| */ | ||
| export default function ErrorBoundary({ error, retry }: ErrorBoundaryProps) { | ||
| const { mutate } = useSWRConfig() | ||
| useEffect(() => { | ||
| console.error('Unhandled error:', error, error.digest) | ||
| }, [error]) | ||
|
|
||
| return ( | ||
| <div> | ||
| <h1>Something went wrong!</h1> | ||
| <ErrorBox> | ||
| {/* digest is only present in server-side errors */} | ||
| {error.digest && ( | ||
|
robsimmons marked this conversation as resolved.
|
||
| <p> | ||
| Something went wrong on the server. Try again, or contact your administrator with the error code{' '} | ||
| {error.digest} if the problem persists. | ||
| </p> | ||
| )} | ||
| {!error.digest && <p>An unexpected error occurred: {error.message}</p>} | ||
| </ErrorBox> | ||
| <button | ||
| onClick={async () => { | ||
| try { | ||
| // Invalidate all SWR state, but don't re-fetch automatically | ||
| await mutate(() => true, undefined, { revalidate: false }) | ||
| } catch (e) { | ||
| console.error('Failed to clear SWR cache', e) | ||
| } | ||
|
|
||
| //Attempt to recover by re-rendering | ||
| retry() | ||
| }} | ||
| > | ||
| Try again | ||
| </button> | ||
| </div> | ||
| ) | ||
| } | ||
This file contains hidden or 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,12 @@ | ||
| import ErrorBox from './components/ErrorBox' | ||
|
|
||
| export default function Forbidden() { | ||
| return ( | ||
| <div> | ||
| <h1>Not allowed</h1> | ||
| <ErrorBox> | ||
| <p>You don't have access to this page.</p> | ||
| </ErrorBox> | ||
| </div> | ||
| ) | ||
| } |
This file contains hidden or 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,21 @@ | ||
| 'use client' | ||
|
|
||
| interface ErrorBoundaryProps { | ||
| error: Error & { digest?: string } | ||
| } | ||
|
|
||
| /** | ||
| * Error boundary for the app root | ||
| * https://nextjs.org/docs/app/api-reference/file-conventions/error#global-error | ||
| */ | ||
| export default function GlobalError({ error }: ErrorBoundaryProps) { | ||
|
Vtec234 marked this conversation as resolved.
|
||
| return ( | ||
| <html> | ||
| <body> | ||
| <h1>Something went wrong!</h1> | ||
| <p>Contact your administrator if you continue to see this message.</p> | ||
| {error.digest && <p>(Error code {error.digest})</p>} | ||
| </body> | ||
| </html> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.