Skip to content

Commit 07e3a0e

Browse files
committed
fix(apigw): do not throw error when got cname not config error
1 parent 7ffada7 commit 07e3a0e

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

src/modules/apigw/apis.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function apiFactory(actions) {
4141
if (Response.Error.Code.indexOf('ResourceNotFound') === -1) {
4242
throw new TypeError(
4343
`API_APIGW_${action}`,
44-
Response.Error.Message,
44+
`${Response.Error.Code}: ${Response.Error.Message}`,
4545
null,
4646
Response.RequestId,
4747
);

src/modules/apigw/index.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { Capi } = require('@tencent-sdk/capi');
22
const Apis = require('./apis');
3-
const { uniqueArray, camelCaseProperty } = require('../../utils/index');
3+
const { uniqueArray, camelCaseProperty, isArray } = require('../../utils/index');
44

55
class Apigw {
66
constructor(credentials = {}, region) {
@@ -511,20 +511,39 @@ class Apigw {
511511
netType: domainItem.netType ? domainItem.netType : 'OUTER',
512512
protocol: domainProtocol,
513513
};
514-
await this.request({
515-
Action: 'BindSubDomain',
516-
...domainInputs,
517-
});
518-
customDomainOutput.push({
519-
created: true,
520-
subDomain: domainItem.domain,
521-
cname: subDomain,
522-
url: `${domainProtocol.indexOf('https') !== -1 ? 'https' : 'http'}://${
523-
domainItem.domain
524-
}`,
525-
});
526-
console.log(`Custom domain for service ${serviceId} created successfullly.`);
527-
console.log(`Please add CNAME record ${subDomain} for ${domainItem.domain}.`);
514+
515+
try {
516+
await this.request({
517+
Action: 'BindSubDomain',
518+
...domainInputs,
519+
});
520+
521+
customDomainOutput.push({
522+
isBinded: true,
523+
created: true,
524+
subDomain: domainItem.domain,
525+
cname: subDomain,
526+
url: `${domainProtocol.indexOf('https') !== -1 ? 'https' : 'http'}://${
527+
domainItem.domain
528+
}`,
529+
});
530+
console.log(`Custom domain for service ${serviceId} created successfullly.`);
531+
console.log(`Please add CNAME record ${subDomain} for ${domainItem.domain}.`);
532+
} catch (e) {
533+
// User hasn't add cname dns record
534+
if (e.message.indexOf('DomainResolveError') !== -1) {
535+
customDomainOutput.push({
536+
isBinded: false,
537+
created: '创建失败',
538+
subDomain: domainItem.domain,
539+
cname: subDomain,
540+
message: `您的自定义域名还未生效,请给域名 ${domainItem.domain} 添加 CNAME 记录 ${subDomain},等待解析生效后,再次运行 'sls deploy' 完成自定义域名的配置`,
541+
errorMsg: e.message,
542+
});
543+
} else {
544+
throw e;
545+
}
546+
}
528547
}
529548
}
530549

@@ -680,7 +699,7 @@ class Apigw {
680699
// bind custom domain
681700
const customDomains = await this.bindCustomDomain({
682701
serviceId,
683-
subDomain,
702+
subDomain: isArray(subDomain) ? subDomain[0] : subDomain,
684703
inputs,
685704
});
686705
if (customDomains.length > 0) {

0 commit comments

Comments
 (0)