MCPcopy Create free account
hub / github.com/Tele-AI/doc-ops-mcp / sanitizeErrorMessage

Method sanitizeErrorMessage

src/security/errorHandler.ts:6–28  ·  view source on GitHub ↗
(error: any)

Source from the content-addressed store, hash-verified

4
5 // 清理敏感信息的错误消息
6 static sanitizeErrorMessage(error: any): string {
7 if (this.isDevelopment) {
8 return error.message; // 开发环境显示完整信息
9 }
10
11 // 生产环境:移除敏感信息
12 let message = error.message ?? 'An error occurred';
13
14 // 移除文件路径
15 message = message.replace(/\/[^\s]+/g, '[path]');
16
17 // 移除用户名
18 message = message.replace(/\/home\/[^\/]+/g, '/home/[user]');
19 message = message.replace(/\/Users\/[^\/]+/g, '/Users/[user]');
20
21 // 移除 IP 地址
22 message = message.replace(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g, '[ip]');
23
24 // 移除端口号
25 message = message.replace(/:\d{2,5}/g, ':[port]');
26
27 return message;
28 }
29
30 // 记录错误但不泄露敏感信息
31 static logError(context: string, error: any): void {

Callers 2

logErrorMethod · 0.95
readDocumentFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected