Skip to content

Commit 316f218

Browse files
authored
fix(flat-components): add cases where the backend does not return error messages (netless-io#1788)
1 parent 7b482df commit 316f218

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

packages/flat-components/src/utils/errorTip.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ export const errorTips = (e: unknown): void => {
88
}
99

1010
if (isServerRequestError(e)) {
11-
void message.error({
12-
content: FlatI18n.t(e.errorMessage),
13-
key: e.errorMessage,
14-
});
11+
if (e.errorMessage) {
12+
void message.error({
13+
content: FlatI18n.t(e.errorMessage),
14+
key: e.errorCode,
15+
});
16+
} else {
17+
void message.error({
18+
content: FlatI18n.t("error-code-error", { code: `${e.errorCode}` }),
19+
key: e.errorCode,
20+
});
21+
}
22+
} else if ((e as Error).message) {
23+
const { message: content, message: key } = e as Error;
24+
void message.error({ content, key });
25+
} else {
26+
void message.error({ content: FlatI18n.t("unknown-error"), key: "unknown" });
1527
}
16-
17-
const { message: content, message: key } = e as Error;
18-
void message.error({ content, key });
1928
};

packages/flat-i18n/locales/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,5 +552,7 @@
552552
"invalid-directory-name-tips": "The directory name cannot contain the following characters: \\ /",
553553
"new-directory": "New Directory",
554554
"local-file": "Local File",
555-
"new": "New"
555+
"new": "New",
556+
"error-code-error": "An error occurred, error code: {code}",
557+
"unknown-error": "Unknown error"
556558
}

packages/flat-i18n/locales/zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,5 +552,7 @@
552552
"invalid-directory-name-tips": "文件名不能包含以下字符: \\\\ /",
553553
"new-directory": "新建文件夹",
554554
"local-file": "本地文件",
555-
"new": "新建"
555+
"new": "新建",
556+
"error-code-error": "出现错误,错误码:{code}",
557+
"unknown-error": "未知错误"
556558
}

packages/flat-server-api/src/error.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,5 @@ export class ServerRequestError extends Error {
123123
}
124124

125125
export function isServerRequestError(error: unknown): error is ServerRequestError {
126-
return (
127-
error instanceof Error &&
128-
Object.prototype.hasOwnProperty.call(error, "errorCode") &&
129-
Object.prototype.hasOwnProperty.call(error, "errorMessage")
130-
);
126+
return error instanceof Error && Object.prototype.hasOwnProperty.call(error, "errorCode");
131127
}

0 commit comments

Comments
 (0)