material-ui-error-reporting
Simple error reporting component for your material-ui application.
Installation
yarn add material-ui-error-reporting
Or with npm
npm i --save material-ui-error-reporting
Usage example
Component:
;;;;// ...static defaultProps =error:action: ''error: null;static propTypes =error: PropTypesobjectdispatch: PropTypesfunc;{return<div><ErrorReportingopen=thispropserrorerror !== nullaction=thispropserroractionerror=thispropserrorerror/></div>;}{returnerror: stateerrors;}mapStoreToPropsApp;
Reducer:
;;let initialState =action: ''error: null;const errors = {};
Action:
const id = '@@app/' + name;const REQUESTING = ;const RECEIVED = ;const FAILED = ;const ERROR_ADD = ;const newAction = type payload;const requesting = ;const received = ;const failed = ;const errorAdd = ;
Some provider pushing an error:
const url = '...';const provide = {;return;};
Properties
For snackbar props please see material-ui docs.
Name | Type | Default | Description |
---|---|---|---|
open | boolean |
false |
State of the snackbar, opened or closed. |
action | string |
'' |
Name of the action where error happened. |
error | string|Error |
null |
Actual error, it should have toString() method. |
autoHideDuration | number |
10000 |
Snackbar prop. |
getMessage | function |
(props) => props.action + ': ' + props.error |
Pure function which will receive props as first argument and must return a string which should contain error message. Default implementation is a concatenation of the action with error delimited by : . |
style | object |
{backgroundColor: red900, color: grey50} |
Object with the styles for style , contentStyle and bodyStyle of snackbar(will receive a copy into each of this props). |
onError | function |
(error, action = '') => undefined |
Will be called when component props receives non null error . |
onClose | function |
(reason, error, action = '') => undefined |
Will be called when error message closes. |