@lark-apaas/miaoda-cli 0.1.3-alpha.a25d692 → 0.1.3-alpha.b499e4d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api/file/client.js
CHANGED
|
@@ -90,7 +90,20 @@ const BIZ_ERR_MAP = new Map(Object.entries({
|
|
|
90
90
|
message: 'A file at this path already exists',
|
|
91
91
|
hint: 'Rename the target or delete the existing file first (`miaoda file rm`).',
|
|
92
92
|
},
|
|
93
|
+
// k_ec_000040:file-storage 上游引擎层连不上下游服务(依赖抖动 / 远端 RPC 失败)。
|
|
94
|
+
// 文案不向用户暴露内部 code,统一成 INTERNAL_API_ERROR + 重试引导。
|
|
95
|
+
k_ec_000040: {
|
|
96
|
+
code: 'INTERNAL_API_ERROR',
|
|
97
|
+
message: 'Service temporarily unavailable',
|
|
98
|
+
hint: 'Please retry the command. If it keeps failing, share the x-tt-logid (via --verbose) with the on-call team.',
|
|
99
|
+
},
|
|
93
100
|
}));
|
|
101
|
+
// k_ec_* 命名空间是 file-storage 引擎层通用错误(基础设施 / 上游 RPC),不是
|
|
102
|
+
// 用户输入问题。无显式条目时统一兜底成 INTERNAL_API_ERROR + 重试 hint,避免
|
|
103
|
+
// 暴露内部 code 给最终用户。
|
|
104
|
+
function isEngineCommonError(code) {
|
|
105
|
+
return /^k_ec_\d+$/.test(code);
|
|
106
|
+
}
|
|
94
107
|
function ensureSuccess(body) {
|
|
95
108
|
// 后端 envelope 字段历史遗留多种命名:
|
|
96
109
|
// - ErrorCode / error_code: 部分接口
|
|
@@ -106,6 +119,15 @@ function ensureSuccess(body) {
|
|
|
106
119
|
next_actions: mapped.hint ? [mapped.hint] : undefined,
|
|
107
120
|
});
|
|
108
121
|
}
|
|
122
|
+
// k_ec_* 引擎层错误统一兜底:用户视角是"服务暂时不可用",重试即可,
|
|
123
|
+
// 不要把 `File API error [k_ec_000xxx]: <内部翻译>` 这种半成品文案抛给用户。
|
|
124
|
+
if (isEngineCommonError(code)) {
|
|
125
|
+
throw new error_1.AppError('INTERNAL_API_ERROR', 'Service temporarily unavailable', {
|
|
126
|
+
next_actions: [
|
|
127
|
+
`Please retry the command. If it keeps failing, share the x-tt-logid (via --verbose) with the on-call team. (upstream code: ${code})`,
|
|
128
|
+
],
|
|
129
|
+
});
|
|
130
|
+
}
|
|
109
131
|
throw new error_1.AppError(`FILE_API_${code}`, `File API error [${code}]: ${backendMsg}`);
|
|
110
132
|
}
|
|
111
133
|
/** 从 HttpError 的 response 里尝试读 body,用于拿后端返的业务 ErrorCode。 */
|
|
@@ -130,6 +152,24 @@ async function mapHttpError(err, opts) {
|
|
|
130
152
|
if (body) {
|
|
131
153
|
const code = body.ErrorCode ?? body.error_code ?? '';
|
|
132
154
|
if (code && code !== '0') {
|
|
155
|
+
const mapped = BIZ_ERR_MAP.get(code);
|
|
156
|
+
if (mapped) {
|
|
157
|
+
const msg = body.ErrorMessage ??
|
|
158
|
+
body.error_message ??
|
|
159
|
+
body.Message ??
|
|
160
|
+
mapped.message ??
|
|
161
|
+
err.message;
|
|
162
|
+
throw new error_1.AppError(mapped.code, mapped.message ?? msg, {
|
|
163
|
+
next_actions: mapped.hint ? [mapped.hint] : undefined,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (isEngineCommonError(code)) {
|
|
167
|
+
throw new error_1.AppError('INTERNAL_API_ERROR', 'Service temporarily unavailable', {
|
|
168
|
+
next_actions: [
|
|
169
|
+
`Please retry the command. If it keeps failing, share the x-tt-logid (via --verbose) with the on-call team. (upstream code: ${code})`,
|
|
170
|
+
],
|
|
171
|
+
});
|
|
172
|
+
}
|
|
133
173
|
const msg = body.ErrorMessage ?? body.error_message ?? body.Message ?? err.message;
|
|
134
174
|
throw new error_1.AppError(`FILE_API_${code}`, `File API error [${code}]: ${msg}`);
|
|
135
175
|
}
|
|
@@ -212,9 +212,29 @@ Examples:
|
|
|
212
212
|
`);
|
|
213
213
|
fileCmd
|
|
214
214
|
.command('quota')
|
|
215
|
-
.summary('
|
|
215
|
+
.summary('查看文件存储的用量与配额')
|
|
216
|
+
.description('查看文件存储的用量与配额。')
|
|
216
217
|
.usage('[flags]')
|
|
217
218
|
.action(async function () {
|
|
218
219
|
await (0, index_1.handleFileQuota)(this.optsWithGlobals());
|
|
219
|
-
})
|
|
220
|
+
})
|
|
221
|
+
.addHelpText('after', `
|
|
222
|
+
Examples:
|
|
223
|
+
$ miaoda file quota
|
|
224
|
+
Storage: 150 MB / 1 GB (15%)
|
|
225
|
+
Files: 42
|
|
226
|
+
|
|
227
|
+
# --json
|
|
228
|
+
$ miaoda file quota --json
|
|
229
|
+
{
|
|
230
|
+
"data": {
|
|
231
|
+
"storage_used_bytes": 157286400,
|
|
232
|
+
"storage_quota_bytes": 1073741824,
|
|
233
|
+
"usage_percent": 15,
|
|
234
|
+
"files": 42
|
|
235
|
+
},
|
|
236
|
+
"next_cursor": null,
|
|
237
|
+
"has_more": false
|
|
238
|
+
}
|
|
239
|
+
`);
|
|
220
240
|
}
|