-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: moved forwardError to its own file, updated extractErrorDet…
…ails to use array destructuring, added comments
- Loading branch information
1 parent
36d5aae
commit 7e70f4b
Showing
3 changed files
with
36 additions
and
21 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
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,29 @@ | ||
import extractErrorDetails from "./extractErrorDetails"; | ||
|
||
/** | ||
* Forwards an error to the window.onerror handler. | ||
* | ||
* @param {Error} error - The error object. | ||
* @param {Object} info - Additional info, including component stack trace. | ||
*/ | ||
const forwardError = (error, info) => { | ||
const { filename, lineNumber, column } = extractErrorDetails( | ||
info.componentStack | ||
); | ||
|
||
// Call window.onerror to send the error to the error logging system. | ||
if (window.onerror) { | ||
window.onerror( | ||
`${error.name}: ${error.message}`, | ||
filename, | ||
lineNumber, | ||
column, | ||
{ | ||
...info, | ||
stack: info.componentStack | ||
} | ||
); | ||
} | ||
}; | ||
|
||
export default forwardError; |