Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(error-handling): introduce unified and configurable error handli…
- Loading branch information
Showing
19 changed files
with
631 additions
and
297 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
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
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
File renamed without changes.
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,32 @@ | ||
import React, { Component } from "react" | ||
|
||
export const componentDidCatch = console.error | ||
|
||
const isClassComponent = component => component.prototype && component.prototype.isReactComponent | ||
|
||
export const withErrorBoundary = (getSystem) => (WrappedComponent) => { | ||
const { getComponent, fn } = getSystem() | ||
const ErrorBoundary = getComponent("ErrorBoundary") | ||
const targetName = fn.getDisplayName(WrappedComponent) | ||
|
||
class WithErrorBoundary extends Component { | ||
render() { | ||
return ( | ||
<ErrorBoundary targetName={targetName} getComponent={getComponent} fn={fn}> | ||
<WrappedComponent {...this.props} {...this.context} /> | ||
</ErrorBoundary> | ||
) | ||
} | ||
} | ||
WithErrorBoundary.displayName = `WithErrorBoundary(${targetName})` | ||
if (isClassComponent(WrappedComponent)) { | ||
/** | ||
* We need to handle case of class components defining a `mapStateToProps` public method. | ||
* Components with `mapStateToProps` public method cannot be wrapped. | ||
*/ | ||
WithErrorBoundary.prototype.mapStateToProps = WrappedComponent.prototype.mapStateToProps | ||
} | ||
|
||
return WithErrorBoundary | ||
} | ||
|
Oops, something went wrong.