-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class PagenoteError extends Error { | ||
private readonly data: any; | ||
constructor(message:string, data:any) { | ||
super(message); // 调用父类的构造函数 | ||
this.name = this.constructor.name; // 设置错误名称 | ||
this.message = message; // 错误信息 | ||
this.data = data; | ||
|
||
// 错误堆栈信息 | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(this, this.constructor); | ||
} else { | ||
this.stack = (new Error()).stack; | ||
} | ||
|
||
// 执行自定义程序,例如上报服务器 | ||
this.reportError(); | ||
} | ||
|
||
// 自定义方法,用于上报错误 | ||
reportError() { | ||
const { data, message } = this; | ||
console.log(`上报错误: ${message}, 数据: ${JSON.stringify(data)}`); | ||
|
||
} | ||
} |