| 1 | export const mapError = (e) => { |
| 2 | let msg = e; |
| 3 | if (e instanceof Error) { |
| 4 | msg = [e.message, e.stack].join("\n"); |
| 5 | } else if (typeof e !== "string") { |
| 6 | msg = e.toString(); |
| 7 | } |
| 8 | const map = { |
| 9 | // 'fetch error': '网络错误', |
| 10 | }; |
| 11 | for (let key in map) { |
| 12 | if (msg.includes(key)) { |
| 13 | let error = map[key]; |
| 14 | // regex PluginReleaseDocFormatError:-11 |
| 15 | const regex = new RegExp(`${key}:(-?\\d+)`); |
| 16 | const match = msg.match(regex); |
| 17 | if (match) { |
| 18 | error += `(${match[1]})`; |
| 19 | } |
| 20 | return error; |
| 21 | } |
| 22 | } |
| 23 | return msg; |
| 24 | }; |