error-boundary.js 857 B

12345678910111213141516171819202122232425262728293031
  1. import React from 'react'
  2. import { ErrorBoundary } from 'react-error-boundary'
  3. function errorHandler(error, componentStack) {
  4. if (window.Raven) {
  5. Raven.captureException(error, {
  6. extra: { componentStack },
  7. tags: { mechanism: 'react-error-boundary' }
  8. })
  9. }
  10. }
  11. function withErrorBoundary(WrappedComponent, FallbackComponent) {
  12. function ErrorBoundaryWrapper(props) {
  13. return (
  14. <ErrorBoundary
  15. fallbackRender={FallbackComponent || null}
  16. onError={errorHandler}
  17. >
  18. <WrappedComponent {...props} />
  19. </ErrorBoundary>
  20. )
  21. }
  22. ErrorBoundaryWrapper.propTypes = WrappedComponent.propTypes
  23. ErrorBoundaryWrapper.displayName = `WithErrorBoundaryWrapper${WrappedComponent.displayName ||
  24. WrappedComponent.name ||
  25. 'Component'}`
  26. return ErrorBoundaryWrapper
  27. }
  28. export default withErrorBoundary