Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit a98c58f

Browse files
committed
refactor: change custom error name
1 parent 73c905b commit a98c58f

34 files changed

Lines changed: 162 additions & 162 deletions

bin/cloudbase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ if (process.argv.length < 3) {
5959
program.parse(process.argv)
6060

6161
function errorHandler(err) {
62-
const stackIngoreErrors = ['TencentCloudSDKHttpException', 'TcbError']
62+
const stackIngoreErrors = ['TencentCloudSDKHttpException', 'CloudBaseError']
6363
// 忽略自定义错误的错误栈
6464
if (err.stack && !stackIngoreErrors.includes(err.name)) {
6565
console.log(err.stack)

lib/commands/env-domain.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ commander_1.default
4444
default: true
4545
});
4646
if (!confirm) {
47-
throw new error_1.TcbError('操作终止!');
47+
throw new error_1.CloudBaseError('操作终止!');
4848
}
4949
let envDomains = await env_1.getEnvAuthDomains({
5050
envId: assignEnvId
@@ -57,7 +57,7 @@ commander_1.default
5757
}
5858
});
5959
if (exitDomains.length) {
60-
throw new error_1.TcbError(`域名 [${exitDomains.join(', ')}] 已存在!`);
60+
throw new error_1.CloudBaseError(`域名 [${exitDomains.join(', ')}] 已存在!`);
6161
}
6262
await env_1.createEnvDomain({
6363
envId: assignEnvId,
@@ -94,7 +94,7 @@ commander_1.default
9494
default: true
9595
});
9696
if (!confirm) {
97-
throw new error_1.TcbError('操作终止!');
97+
throw new error_1.CloudBaseError('操作终止!');
9898
}
9999
const domainIds = domains
100100
.filter(item => selectDomains.includes(item.Domain))

lib/commands/env.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async function checkEnvAvailability(envId) {
5050
retry++;
5151
}
5252
if (retry > MAX_TRY) {
53-
reject(new error_1.TcbError('环境初始化查询超时,请稍后通过 cloudbase env:list 查看环境状态'));
53+
reject(new error_1.CloudBaseError('环境初始化查询超时,请稍后通过 cloudbase env:list 查看环境状态'));
5454
}
5555
}, 1000);
5656
});
@@ -60,7 +60,7 @@ commander_1.default
6060
.description('创建新的云环境')
6161
.action(async function (alias) {
6262
if (!alias) {
63-
throw new error_1.TcbError('环境名称不能为空!');
63+
throw new error_1.CloudBaseError('环境名称不能为空!');
6464
}
6565
const res = await env_1.createEnv({
6666
alias

lib/commands/functions.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ async function getConfigFunctions() {
2424
if (!config.functions ||
2525
!Array.isArray(config.functions) ||
2626
!config.functions.length) {
27-
throw new error_1.TcbError('函数配置不存在');
27+
throw new error_1.CloudBaseError('函数配置不存在');
2828
}
2929
const { functions } = config;
3030
functions.forEach(func => {
3131
if (!func.name) {
32-
throw new error_1.TcbError('云函数名称不能为空');
32+
throw new error_1.CloudBaseError('云函数名称不能为空');
3333
}
3434
if (typeof func.config.timeout !== 'undefined') {
3535
const timeout = Number(func.config.timeout);
3636
if (!Number.isInteger(timeout)) {
37-
throw new error_1.TcbError('超时时间必需为整数');
37+
throw new error_1.CloudBaseError('超时时间必需为整数');
3838
}
3939
if (timeout < 1 || timeout > 20) {
40-
throw new error_1.TcbError('超时时间有效值为: 1~20S');
40+
throw new error_1.CloudBaseError('超时时间有效值为: 1~20S');
4141
}
4242
}
4343
});
@@ -62,7 +62,7 @@ commander_1.default
6262
});
6363
isBatchCreating = isBatch;
6464
if (!isBatchCreating) {
65-
throw new error_1.TcbError('请指定部署函数名称!');
65+
throw new error_1.CloudBaseError('请指定部署函数名称!');
6666
}
6767
}
6868
if (isBatchCreating) {
@@ -76,7 +76,7 @@ commander_1.default
7676
}
7777
const newFunction = functions.find(item => item.name === name);
7878
if (!newFunction || !newFunction.name) {
79-
throw new error_1.TcbError(`函数 ${name} 配置不存在`);
79+
throw new error_1.CloudBaseError(`函数 ${name} 配置不存在`);
8080
}
8181
const createSpinner = ora_1.default('函数部署中...').start();
8282
try {
@@ -126,11 +126,11 @@ commander_1.default
126126
const config = await utils_1.resolveCloudBaseConfig();
127127
const functions = await getConfigFunctions();
128128
if (!name) {
129-
throw new error_1.TcbError('请指定函数名称!');
129+
throw new error_1.CloudBaseError('请指定函数名称!');
130130
}
131131
const func = functions.find(item => item.name === name);
132132
if (!func || !func.name) {
133-
throw new error_1.TcbError(`函数 ${name} 配置不存在`);
133+
throw new error_1.CloudBaseError(`函数 ${name} 配置不存在`);
134134
}
135135
const spinner = ora_1.default(`[${func.name}] 函数代码更新中...`).start();
136136
try {
@@ -156,10 +156,10 @@ commander_1.default
156156
limit = Number(limit);
157157
offset = Number(offset);
158158
if (!Number.isInteger(limit) || !Number.isInteger(offset)) {
159-
throw new error_1.TcbError('limit 和 offset 必须为整数');
159+
throw new error_1.CloudBaseError('limit 和 offset 必须为整数');
160160
}
161161
if (limit < 0 || offset < 0) {
162-
throw new error_1.TcbError('limit 和 offset 必须为大于 0 的整数');
162+
throw new error_1.CloudBaseError('limit 和 offset 必须为大于 0 的整数');
163163
}
164164
const assignEnvId = await utils_1.getEnvId(envId);
165165
const data = await function_1.listFunction({
@@ -208,7 +208,7 @@ commander_1.default
208208
isBatchDelete = reConfirm;
209209
}
210210
if (!isBatchDelete) {
211-
throw new error_1.TcbError('请指定需要删除的云函数名称!');
211+
throw new error_1.CloudBaseError('请指定需要删除的云函数名称!');
212212
}
213213
}
214214
if (isBatchDelete) {
@@ -311,21 +311,21 @@ commander_1.default
311311
const assignEnvId = await utils_1.getEnvId(envId);
312312
let { offset, limit, order, orderBy, error, success, startTime, endTime, reqId: functionRequestId } = options;
313313
if (!name) {
314-
throw new error_1.TcbError('云函数名称不能为空');
314+
throw new error_1.CloudBaseError('云函数名称不能为空');
315315
}
316316
const TimeLength = 19;
317317
if (typeof startTime !== 'undefined' &&
318318
typeof endTime !== 'undefined' &&
319319
(startTime.length !== TimeLength || endTime.length !== TimeLength)) {
320-
throw new error_1.TcbError('时间格式错误,必须为 2019-05-16 20:59:59 类型');
320+
throw new error_1.CloudBaseError('时间格式错误,必须为 2019-05-16 20:59:59 类型');
321321
}
322322
if (new Date(endTime).getTime() < new Date(startTime).getTime()) {
323-
throw new error_1.TcbError('开始时间不能晚于结束时间');
323+
throw new error_1.CloudBaseError('开始时间不能晚于结束时间');
324324
}
325325
const OneDay = 86400000;
326326
if (new Date(endTime).getTime() - new Date(startTime).getTime() >
327327
OneDay) {
328-
throw new error_1.TcbError('endTime 与 startTime 只能相差一天之内');
328+
throw new error_1.CloudBaseError('endTime 与 startTime 只能相差一天之内');
329329
}
330330
let params = {
331331
offset,
@@ -386,7 +386,7 @@ commander_1.default
386386
});
387387
isBathUpdate = isBatch;
388388
if (!isBathUpdate) {
389-
throw new error_1.TcbError('请指定云函数名称!');
389+
throw new error_1.CloudBaseError('请指定云函数名称!');
390390
}
391391
}
392392
const functions = await getConfigFunctions();
@@ -400,7 +400,7 @@ commander_1.default
400400
}
401401
const functionItem = functions.find(item => item.name === name);
402402
if (!functionItem) {
403-
throw new error_1.TcbError('未找到相关函数配置,请检查函数名是否正确');
403+
throw new error_1.CloudBaseError('未找到相关函数配置,请检查函数名是否正确');
404404
}
405405
await function_1.updateFunctionConfig({
406406
functionName: name,
@@ -424,7 +424,7 @@ commander_1.default
424424
});
425425
isBatchCreateTrigger = isBatch;
426426
if (!isBatchCreateTrigger) {
427-
throw new error_1.TcbError('请指定云函数名称!');
427+
throw new error_1.CloudBaseError('请指定云函数名称!');
428428
}
429429
}
430430
const functions = await getConfigFunctions();
@@ -436,11 +436,11 @@ commander_1.default
436436
}
437437
const functionItem = functions.find(item => item.name === name);
438438
if (!functionItem) {
439-
throw new error_1.TcbError('未找到相关函数配置,请检查函数名是否正确');
439+
throw new error_1.CloudBaseError('未找到相关函数配置,请检查函数名是否正确');
440440
}
441441
const { triggers } = functionItem;
442442
if (!triggers || !triggers.length) {
443-
throw new error_1.TcbError('触发器配置不能为空');
443+
throw new error_1.CloudBaseError('触发器配置不能为空');
444444
}
445445
await function_1.createFunctionTriggers({
446446
functionName: name,
@@ -473,7 +473,7 @@ commander_1.default
473473
isBtachDeleteTriggers = reConfirm;
474474
}
475475
if (!isBtachDeleteTriggers) {
476-
throw new error_1.TcbError('请指定云函数名称以及触发器名称!');
476+
throw new error_1.CloudBaseError('请指定云函数名称以及触发器名称!');
477477
}
478478
}
479479
if (isBtachDeleteTriggers) {
@@ -492,7 +492,7 @@ commander_1.default
492492
});
493493
isBatchDeleteFunctionTriggers = isBatch;
494494
if (!isBatchDeleteFunctionTriggers) {
495-
throw new error_1.TcbError('请指定云函数名称以及触发器名称!');
495+
throw new error_1.CloudBaseError('请指定云函数名称以及触发器名称!');
496496
}
497497
}
498498
if (isBatchDeleteFunctionTriggers) {
@@ -504,7 +504,7 @@ commander_1.default
504504
});
505505
}
506506
if (!triggerName) {
507-
throw new error_1.TcbError('触发器名称不能为空');
507+
throw new error_1.CloudBaseError('触发器名称不能为空');
508508
}
509509
function_1.deleteFunctionTrigger({
510510
functionName,
@@ -527,7 +527,7 @@ commander_1.default
527527
});
528528
isBatchInvoke = isBatch;
529529
if (!isBatchInvoke) {
530-
throw new error_1.TcbError('请指定云函数名称!');
530+
throw new error_1.CloudBaseError('请指定云函数名称!');
531531
}
532532
}
533533
let params;
@@ -537,7 +537,7 @@ commander_1.default
537537
}
538538
catch (e) {
539539
console.log(e);
540-
throw new error_1.TcbError('jsonStringParams 参数不是正确的 JSON 字符串');
540+
throw new error_1.CloudBaseError('jsonStringParams 参数不是正确的 JSON 字符串');
541541
}
542542
}
543543
const functions = await getConfigFunctions();
@@ -550,7 +550,7 @@ commander_1.default
550550
}
551551
const func = functions.find(item => item.name === name);
552552
if (!func) {
553-
throw new error_1.TcbError('未找到相关函数配置,请检查函数名是否正确');
553+
throw new error_1.CloudBaseError('未找到相关函数配置,请检查函数名是否正确');
554554
}
555555
const result = await function_1.invokeFunction({
556556
functionName: name,
@@ -568,7 +568,7 @@ commander_1.default
568568
const assignEnvId = await utils_1.getEnvId(envId);
569569
const { force } = options;
570570
if (!functionName || !newFunctionName) {
571-
throw new error_1.TcbError('请指定函数名称!');
571+
throw new error_1.CloudBaseError('请指定函数名称!');
572572
}
573573
await function_1.copyFunction({
574574
force,

lib/commands/init.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ commander_1.default
2929
load.succeed('获取环境列表成功');
3030
const envs = envData.map(item => `${item.EnvId}:${item.PackageName}`);
3131
if (!envs.length) {
32-
throw new error_1.TcbError('没有可以使用的环境,请先开通云开发环境(https://console.cloud.tencent.com/tcb)');
32+
throw new error_1.CloudBaseError('没有可以使用的环境,请先开通云开发环境(https://console.cloud.tencent.com/tcb)');
3333
}
3434
const { env } = await inquirer_1.default.prompt({
3535
type: 'list',
@@ -53,7 +53,7 @@ commander_1.default
5353
default: false
5454
});
5555
if (!cover) {
56-
throw new error_1.TcbError('操作终止!');
56+
throw new error_1.CloudBaseError('操作终止!');
5757
}
5858
else {
5959
fs_extra_1.default.removeSync(projectPath);

lib/commands/login.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ commander_1.default
5555
skey = _skey;
5656
}
5757
if (!secretId || !secretKey) {
58-
throw new error_1.TcbError('SecretID 或 SecretKey 不能为空');
58+
throw new error_1.CloudBaseError('SecretID 或 SecretKey 不能为空');
5959
}
6060
const cloudSpinner = ora_1.default('正在验证腾讯云密钥...').start();
6161
const res = await auth_1.login({

lib/commands/server.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ function checkServers(servers) {
1212
const names = {};
1313
servers.forEach((server) => {
1414
if (!server.name) {
15-
throw new error_1.TcbError('Every server must have a name.');
15+
throw new error_1.CloudBaseError('Every server must have a name.');
1616
}
1717
else if (!server.path) {
18-
throw new error_1.TcbError('未指定发布目录');
18+
throw new error_1.CloudBaseError('未指定发布目录');
1919
}
2020
else if (server.type != types_1.ServerLanguageType.node) {
21-
throw new error_1.TcbError(`Unsupported deploy type: "${server.type}"`);
21+
throw new error_1.CloudBaseError(`Unsupported deploy type: "${server.type}"`);
2222
}
2323
else if (names[server.name]) {
24-
throw new error_1.TcbError(`Duplicated deploy name: "${server.name}"`);
24+
throw new error_1.CloudBaseError(`Duplicated deploy name: "${server.name}"`);
2525
}
2626
names[server.name] = true;
2727
});
@@ -45,7 +45,7 @@ commander_1.default
4545
const sshConfig = await utils_1.getSSH();
4646
servers.forEach(async (server) => {
4747
if (!server.path) {
48-
throw new error_1.TcbError('未指定发布目录');
48+
throw new error_1.CloudBaseError('未指定发布目录');
4949
}
5050
await new controller_1.NodeController(Object.assign({ envId }, sshConfig, server, credential)).deploy();
5151
return;

lib/env/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function createEnv({ alias }) {
2828
return res;
2929
}
3030
catch (e) {
31-
throw new error_1.TcbError(`创建环境失败:${e.message}`);
31+
throw new error_1.CloudBaseError(`创建环境失败:${e.message}`);
3232
}
3333
}
3434
exports.createEnv = createEnv;

lib/env/login.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ exports.getLoginConfigList = getLoginConfigList;
3333
async function createLoginConfig({ envId, platform, appId, appSecret }) {
3434
const validPlatform = ['WECHAT-OPEN', 'WECHAT-PUBLIC'];
3535
if (!validPlatform.includes(platform)) {
36-
throw new error_1.TcbError(`Invalid platform value: ${platform}. Now only support 'WECHAT-OPEN', 'WECHAT-PUBLIC'`);
36+
throw new error_1.CloudBaseError(`Invalid platform value: ${platform}. Now only support 'WECHAT-OPEN', 'WECHAT-PUBLIC'`);
3737
}
3838
await tcbService.request('CreateLoginConfig', {
3939
EnvId: envId,
@@ -47,7 +47,7 @@ exports.createLoginConfig = createLoginConfig;
4747
async function updateLoginConfig({ configId, envId, status = 'ENABLE', appId = '', appSecret = '' }) {
4848
const validStatus = ['ENABLE', 'DISABLE'];
4949
if (!validStatus.includes(status)) {
50-
throw new error_1.TcbError(`Invalid status value: ${status}. Only support 'ENABLE', 'DISABLE'`);
50+
throw new error_1.CloudBaseError(`Invalid status value: ${status}. Only support 'ENABLE', 'DISABLE'`);
5151
}
5252
const params = {
5353
EnvId: envId,

lib/error.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
class TcbError extends Error {
3+
class CloudBaseError extends Error {
44
constructor(message, options = {}) {
55
super();
6-
this.name = 'TcbError';
6+
this.name = 'CloudBaseError';
77
this.message = message;
88
this.original = options.original;
99
this.code = options.code;
1010
this.requestId = options.requestId;
1111
}
1212
}
13-
exports.TcbError = TcbError;
13+
exports.CloudBaseError = CloudBaseError;

0 commit comments

Comments
 (0)