Initial clean project import
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
export const mapError = e => {
|
||||
if (e === undefined || e === null) {
|
||||
return "Unknown error";
|
||||
}
|
||||
let msg = e;
|
||||
if (e instanceof Error) {
|
||||
msg = [e.message, e.stack].join("\n");
|
||||
} else if (typeof e !== "string") {
|
||||
msg = e.toString();
|
||||
}
|
||||
const map = {
|
||||
// 'fetch error': '网络错误',
|
||||
};
|
||||
for (let key in map) {
|
||||
if (msg.includes(key)) {
|
||||
let error = map[key];
|
||||
// regex PluginReleaseDocFormatError:-11
|
||||
const regex = new RegExp(`${key}:(-?\\d+)`);
|
||||
const match = msg.match(regex);
|
||||
if (match) {
|
||||
error += `(${match[1]})`;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
Reference in New Issue
Block a user