-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle error console instance and title
- Loading branch information
Showing
7 changed files
with
59 additions
and
43 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
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
12 changes: 0 additions & 12 deletions
12
...ages/next/src/client/components/react-dev-overlay/internal/helpers/capture-stack-trace.ts
This file was deleted.
Oops, something went wrong.
24 changes: 19 additions & 5 deletions
24
packages/next/src/client/components/react-dev-overlay/internal/helpers/console-error.ts
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 |
---|---|---|
@@ -1,15 +1,29 @@ | ||
// To distinguish from React error.digest, we use a different symbol here to determine if the error is from console.error or unhandled promise rejection. | ||
const digestSym = Symbol.for('next.console.error.digest') | ||
const consoleTypeSym = Symbol.for('next.console.error.type') | ||
|
||
// Represent non Error shape unhandled promise rejections or console.error errors. | ||
// Those errors will be captured and displayed in Error Overlay. | ||
type UnhandledError = Error & { digest: 'NEXT_UNHANDLED_ERROR' } | ||
type UnhandledError = Error & { | ||
[digestSym]: 'NEXT_UNHANDLED_ERROR' | ||
[consoleTypeSym]: 'string' | 'error' | ||
} | ||
|
||
export function createUnhandledError(message: string): UnhandledError { | ||
const error = new Error(message) as UnhandledError | ||
error.digest = 'NEXT_UNHANDLED_ERROR' | ||
export function createUnhandledError(message: string | Error): UnhandledError { | ||
const error = ( | ||
typeof message === 'string' ? new Error(message) : message | ||
) as UnhandledError | ||
error[digestSym] = 'NEXT_UNHANDLED_ERROR' | ||
error[consoleTypeSym] = typeof message === 'string' ? 'string' : 'error' | ||
return error | ||
} | ||
|
||
export const isUnhandledConsoleOrRejection = ( | ||
error: any | ||
): error is UnhandledError => { | ||
return error && error.digest === 'NEXT_UNHANDLED_ERROR' | ||
return error && error[digestSym] === 'NEXT_UNHANDLED_ERROR' | ||
} | ||
|
||
export const getUnhandledErrorType = (error: UnhandledError) => { | ||
return error[consoleTypeSym] | ||
} |
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
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