All Projects → x-orpheus → catch-react-error

x-orpheus / catch-react-error

Licence: other
A framework using React Boundary handles error easily

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to catch-react-error

Failure
failure is a utility package for handling application errors.
Stars: ✭ 187 (+379.49%)
Mutual labels:  error
try-to-catch
functional try-catch wrapper for promises
Stars: ✭ 30 (-23.08%)
Mutual labels:  error
ErrorControlSystem
ErrorControlSystem is a .NET library created to automate handling .NET Windows-Base application exceptions and raise that to a sql server. This exception handler have some features as screen capturing, fetch server date time in exception occurrence time and etc.
Stars: ✭ 30 (-23.08%)
Mutual labels:  error
Human Signals
Human-friendly process signals
Stars: ✭ 223 (+471.79%)
Mutual labels:  error
react-native-easy-state-view
Fully customizable State View for React Native.
Stars: ✭ 21 (-46.15%)
Mutual labels:  error
sfdc-error-playground
Lightning & Apex Error Playground
Stars: ✭ 30 (-23.08%)
Mutual labels:  error
Swift Error Handler
Error handling library for Swift
Stars: ✭ 172 (+341.03%)
Mutual labels:  error
errata
Source code error pretty printing
Stars: ✭ 41 (+5.13%)
Mutual labels:  error
custom-error-test
Compare and test various custom error implementations.
Stars: ✭ 32 (-17.95%)
Mutual labels:  error
koa-better-error-handler
A better error-handler for Lad and Koa. Makes `ctx.throw` awesome (best used with koa-404-handler)
Stars: ✭ 51 (+30.77%)
Mutual labels:  error
Node Common Errors
Common error classes and utility functions
Stars: ✭ 247 (+533.33%)
Mutual labels:  error
error-handler
PSR-15 middleware to handle http errors
Stars: ✭ 13 (-66.67%)
Mutual labels:  error
TrackJS-Node
TrackJS Error Monitoring agent for NodeJS
Stars: ✭ 26 (-33.33%)
Mutual labels:  error
Emperror
The Emperor takes care of all errors personally
Stars: ✭ 201 (+415.38%)
Mutual labels:  error
laravel-exception-notify
Laravel 中异常监控报警通知(Bark、Chanify、钉钉群机器人、Discord、飞书群机器人、邮件、PushDeer、QQ 频道机器人、Server 酱、Slack、Telegram、企业微信群机器人、息知)。
Stars: ✭ 52 (+33.33%)
Mutual labels:  error
Statefulviewcontroller
Placeholder views based on content, loading, error or empty states
Stars: ✭ 2,139 (+5384.62%)
Mutual labels:  error
locerr
❌ locerr (locational error): Library for nice-looking errors in source code
Stars: ✭ 16 (-58.97%)
Mutual labels:  error
custom-exception-middleware
Middleware to catch custom or accidental exceptions
Stars: ✭ 30 (-23.08%)
Mutual labels:  error
Xcode-Error-Collection
总结的Xcode报错问题以及解决方法,希望在开发的路上都可以少走一些弯路。
Stars: ✭ 45 (+15.38%)
Mutual labels:  error
ELog
ELog----日志打印工具,带定位功能
Stars: ✭ 17 (-56.41%)
Mutual labels:  error

catch-react-error

npm Build Status codecov

English | 简体中文

Why we create catch-react-error

Introduction

This package supports both React And React Native.

This project make it easy to protect your react source code。

We combine decorators and React Error Boundaries together.

The React Error Boundaries don't support the Server Side Rendering,so we use try/catch to deal such condition.

The catch-react-error takes only one argument,React Error Boundary Component which we provide DefaultErrorBoundary as the default one.

const catchreacterror = (Boundary = DefaultErrorBoundary) => {};

Demo

we provide some demo, so you can understand the library more clearly

client side render

cd example-client
npm install
npm run dev

server side render

cd example-server
npm install
npm run dev

How to use

1.install catch-react-error

npm install catch-react-error --save

2. Install ES7 Decorator babel plugin

npm install --save-dev @babel/plugin-proposal-decorators
npm install --save-dev @babel/plugin-proposal-class-properties

babel plugin configuration

{
  "plugins": [
    ["@babel/plugin-proposal-decorators", { "legacy": true }],
    ["@babel/plugin-proposal-class-properties", { "loose": true }]
  ]
}

3. import catch-react-error

import catchreacterror from "catch-react-error";

4. Use @catchreacterror on class component

@catchreacterror()
class Count extends React.Component {
  render() {
    const { count } = this.props;
    if (count === 3) {
      throw new Error("count is three");
    }
    return <h1>{count}</h1>;
  }
}

5. Use @catchreacterror on functionc component

function Count({ count }) {
  if (count === 3) {
    throw new Error("count is three");
  }
  return <h1>{count}</h1>;
}

const SaleCount = catchreacterror()(Count);

6. Add a CustomErrorBoundary component

  • First, create an normal Error Boundary Component and change it
class CustomErrorBoundary extends React.Component {
  constructor (props) {
    super (props);
    this.state = {hasError: false};
  }

  static getDerivedStateFromError (error) {
    return {hasError: true};
  }

  componentDidCatch (error, errorInfo) {
      //do something as needed
    reportToMyLogService (error, errorInfo);
  }

  render () {
    if (this.state.hasError) {
      return <h1> Something with my app,fallback ui. </ h1>;
    }
  }

    return this.props.children;
  }
}
  • Second, pass it as the argument
@catchreacterror(CustomErrorBoundary)
class Count extends React.Component {}

or

const SaleCount = catchreacterror(CustomErrorBoundary)(Count);

TODO

  • curried function
  • log to sentry

License

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].