企业开发中,组件众多,甚至组件嵌套组件也很多,所以当成百上千个组件加载起来,难免的会有些意外报错情况,根据现有的开发经验,将react项目里面异常组件定义出来,并给与提示信息而非直接抛出红色错误
这个里面有个额外的知识补充,依据于[Error.captureStackTrace],关于这个方面的知识我也是学习的这个大佬的文章,大家也可以看看:https://segmentfault.com/a/11...
export default class Exception extends Error { /* Exceptions for Remote START */ static CONNECTION_TIMEOUT = '远端请求超时。'; static NO_CONTAINER = '未找到容器。'; /* Exceptions for Remote END */ static PARAMETER_INVALIDE = '无效的参数。'; static TYPE_INCORRECT = '错误的数据类型。'; static LOG_DRIVER_UNDEFINED = '未定义的日志驱动。'; /** * 构造函数。 */ constructor(message) { super(); if ('captureStackTrace' in Error) { Error.captureStackTrace(this, Exception); } this.name = 'WHException'; this.message = message; }}
使用此文件一般可以放在Action里面