fix: 修复京东云报错不准确的bug

This commit is contained in:
xiaojunnuo
2026-03-17 00:05:53 +08:00
parent d01bfbec96
commit 10dd89ae62
7 changed files with 64 additions and 64 deletions
+1 -1
View File
@@ -174,7 +174,7 @@ export default async (client, userOpts) => {
} catch (e) { } catch (e) {
log(`[auto] [${d}] challengeCreateFn threw error: ${e.message}`); log(`[auto] [${d}] challengeCreateFn threw error: ${e.message || e}`);
await deactivateAuth(e); await deactivateAuth(e);
throw e; throw e;
} }
@@ -244,10 +244,11 @@ export class AccessService extends BaseService<AccessEntity> {
} }
const newAccess = { const newAccess = {
...access, ...access,
userId:-1,
id: undefined, id: undefined,
projectId, projectId,
} }
await this.add(newAccess); await this.repository.save(newAccess);
return newAccess.id; return newAccess.id;
} }
} }
@@ -70,11 +70,11 @@ export class JDCloudAccess extends BaseAccess {
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> { async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
const pager = new Pager(req); const pager = new Pager(req);
const service = await this.getJDDomainService(); const service = await this.getJDDomainService();
const domainRes = await service.describeDomains({ const domainRes = await this.catchCall(() => service.describeDomains({
domainName: req.searchKey, domainName: req.searchKey,
pageNumber: pager.pageNo, pageNumber: pager.pageNo,
pageSize: pager.pageSize, pageSize: pager.pageSize,
}) }))
let list = domainRes.result?.dataList || [] let list = domainRes.result?.dataList || []
list = list.map((item: any) => ({ list = list.map((item: any) => ({
id: item.domainId, id: item.domainId,
@@ -85,7 +85,17 @@ export class JDCloudAccess extends BaseAccess {
list, list,
}; };
} }
async catchCall<T=any>(fn: () => Promise<T>): Promise<T> {
try {
return await fn();
} catch (e) {
if (e.error) {
this.ctx.logger.error(JSON.stringify(e.error))
throw new Error(JSON.stringify(e.error))
}
throw e
}
}
} }
new JDCloudAccess(); new JDCloudAccess();
@@ -54,8 +54,7 @@ export class JDCloudDnsProvider extends AbstractDnsProvider {
* weight Integer False 解析记录的权重,目前支持权重的有:A/AAAA/CNAME/JNAMEA/AAAA权重范围:0-100、CNAME/JNAME权重范围:1-100。 * weight Integer False 解析记录的权重,目前支持权重的有:A/AAAA/CNAME/JNAMEA/AAAA权重范围:0-100、CNAME/JNAME权重范围:1-100。
* viewValue Integer True 解析线路的ID,请调用describeViewTree接口获取基础解 * viewValue Integer True 解析线路的ID,请调用describeViewTree接口获取基础解
*/ */
try{ const res = await this.access.catchCall(() => service.createResourceRecord({
const res = await service.createResourceRecord({
domainId: domainId, domainId: domainId,
req: { req: {
hostRecord: hostRecord, hostRecord: hostRecord,
@@ -64,31 +63,21 @@ export class JDCloudDnsProvider extends AbstractDnsProvider {
ttl: 200, ttl: 200,
viewValue: -1, viewValue: -1,
} }
}) }))
return { return {
recordId: res.result.dataList.id, recordId: res.result.dataList.id,
domainId: domainId domainId: domainId
}; };
}catch (e) {
if (e.error){
this.logger.error(JSON.stringify(e.error))
throw new Error(JSON.stringify(e.error))
}
throw e
}
} }
async removeRecord(options: RemoveRecordOptions<any>): Promise<any> { async removeRecord(options: RemoveRecordOptions<any>): Promise<any> {
const record = options.recordRes; const record = options.recordRes;
const service = await this.getJDDomainService(); const service = await this.getJDDomainService();
await service.deleteResourceRecord({ await this.access.catchCall(() => service.deleteResourceRecord({
domainId: record.domainId, domainId: record.domainId,
resourceRecordId: record.recordId resourceRecordId: record.recordId
}) }))
} }
private async getJDDomainService() { private async getJDDomainService() {
@@ -71,7 +71,7 @@ export class JDCloudDeployToCDN extends AbstractTaskPlugin {
this.logger.info(`开始上传证书`); this.logger.info(`开始上传证书`);
const sslService = await this.getSslClient(access); const sslService = await this.getSslClient(access);
const res = await sslService.uploadCert({ const res = await access.catchCall(() => sslService.uploadCert({
// certName String True 证书名称 // certName String True 证书名称
// keyFile String True 私钥 // keyFile String True 私钥
// certFile String True 证书 // certFile String True 证书
@@ -80,7 +80,7 @@ export class JDCloudDeployToCDN extends AbstractTaskPlugin {
keyFile: certInfo.key, keyFile: certInfo.key,
certFile: certInfo.crt, certFile: certInfo.crt,
aliasName: certName aliasName: certName
}); }));
certId = res.result.certId; certId = res.result.certId;
} }
@@ -152,10 +152,10 @@ export class JDCloudDeployToCDN extends AbstractTaskPlugin {
* pageNumber Integer False 1 pageNumber,默认值1 * pageNumber Integer False 1 pageNumber,默认值1
* pageSize * pageSize
*/ */
const res = await service.getDomainList({ const res = await access.catchCall(() => service.getDomainList({
pageNumber: 1, pageNumber: 1,
pageSize: 50 pageSize: 50
}); }));
// @ts-ignore // @ts-ignore
const list = res?.result?.domains; const list = res?.result?.domains;
if (!list || list.length === 0) { if (!list || list.length === 0) {
@@ -85,7 +85,7 @@ export class JDCloudUpdateCert extends AbstractTaskPlugin {
const certInfo = this.cert as CertInfo const certInfo = this.cert as CertInfo
for (const certId of this.certIds) { for (const certId of this.certIds) {
this.logger.info(`开始更新证书:${certId}`) this.logger.info(`开始更新证书:${certId}`)
const res = await service.updateCert({ const res = await access.catchCall(() => service.updateCert({
/* /*
@param {string} opts.certId - 证书Id @param {string} opts.certId - 证书Id
@param {string} opts.certId - 证书ID @param {string} opts.certId - 证书ID
@@ -96,7 +96,7 @@ export class JDCloudUpdateCert extends AbstractTaskPlugin {
certId, certId,
certFile: certInfo.crt, certFile: certInfo.crt,
keyFile:certInfo.key, keyFile:certInfo.key,
}) }))
this.logger.info(`更新证书${certId}成功:${JSON.stringify(res)}`); this.logger.info(`更新证书${certId}成功:${JSON.stringify(res)}`);
await this.ctx.utils.sleep(2000) await this.ctx.utils.sleep(2000)
} }
@@ -126,10 +126,10 @@ export class JDCloudUpdateCert extends AbstractTaskPlugin {
* pageNumber Integer False 1 pageNumber,默认值1 * pageNumber Integer False 1 pageNumber,默认值1
* pageSize * pageSize
*/ */
const res = await service.describeCerts({ const res = await access.catchCall(() => service.describeCerts({
pageNumber: 1, pageNumber: 1,
pageSize: 100, pageSize: 100,
}) }))
// @ts-ignore // @ts-ignore
const list = res?.result?.certListDetails const list = res?.result?.certListDetails
if (!list || list.length === 0) { if (!list || list.length === 0) {
@@ -61,7 +61,7 @@ export class JDCloudUploadCert extends AbstractTaskPlugin {
const service = await this.getClient(access); const service = await this.getClient(access);
const certInfo = this.cert as CertInfo; const certInfo = this.cert as CertInfo;
const res = await service.uploadCert({ const res = await access.catchCall(() => service.uploadCert({
/* /*
@param {string} opts.certName - 证书名称 @param {string} opts.certName - 证书名称
@param {string} opts.keyFile - 私钥 @param {string} opts.keyFile - 私钥
@@ -71,7 +71,7 @@ export class JDCloudUploadCert extends AbstractTaskPlugin {
certName: this.appendTimeSuffix(this.certName || "certd"), certName: this.appendTimeSuffix(this.certName || "certd"),
certFile: certInfo.crt, certFile: certInfo.crt,
keyFile: certInfo.key keyFile: certInfo.key
}); }));
this.jdcloudCertId = res.result.certId; this.jdcloudCertId = res.result.certId;
this.logger.info(`上传证书成功:${JSON.stringify(res)}`); this.logger.info(`上传证书成功:${JSON.stringify(res)}`);
} }