Skip to content

Commit 6fae687

Browse files
authored
fix(scf): optimize function name error message (#223)
* fix(scf): optimize function name error message * test: fix case * test: fix layer parameter compare
1 parent 9d9648a commit 6fae687

File tree

5 files changed

+28
-37
lines changed

5 files changed

+28
-37
lines changed

__tests__/cls.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ describe('Cls', () => {
7575
topicId: 'e9e38c86-c7ba-475b-a852-6305880d2212',
7676
interval: 3600,
7777
});
78-
console.log('logs', res);
7978
expect(res).toBeInstanceOf(Array);
8079
});
8180
});

__tests__/scf.sp.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ScfDeployInputs } from '../src/modules/scf/interface';
22
import { sleep } from '@ygkit/request';
33
import { Scf } from '../src';
44

5-
describe('Scf - singapore', () => {
5+
describe('Scf - special', () => {
66
const credentials = {
77
SecretId: process.env.TENCENT_SECRET_ID,
88
SecretKey: process.env.TENCENT_SECRET_KEY,

__tests__/scf.test.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,11 @@ describe('Scf', () => {
190190
expect(outputs.AsyncRunEnable).toBe('FALSE');
191191
expect(outputs.Status).toBe('Active');
192192
expect(outputs.EipConfig).toEqual({ EipFixed: 'TRUE', Eips: expect.any(Array) });
193-
expect(outputs.Layers).toEqual([
194-
{
195-
LayerName: layerInputs.name,
196-
LayerVersion: expect.any(Number),
197-
CompatibleRuntimes: layerInputs.runtimes,
198-
Description: layerInputs.description,
199-
LicenseInfo: '',
200-
AddTime: expect.any(String),
201-
Status: 'Active',
202-
Src: 'Default',
203-
},
204-
]);
193+
194+
expect(outputs.Layers[0].LayerName).toBe(layerInputs.name);
195+
expect(outputs.Layers[0].CompatibleRuntimes).toEqual(layerInputs.runtimes);
196+
expect(outputs.Layers[0].Description).toBe(layerInputs.description);
197+
205198
expect(outputs.PublicNetConfig).toEqual({
206199
PublicNetStatus: 'ENABLE',
207200
EipConfig: { EipStatus: 'ENABLE', EipAddress: expect.any(Array) },
@@ -348,18 +341,11 @@ describe('Scf', () => {
348341
expect(outputs.AsyncRunEnable).toBe('FALSE');
349342
expect(outputs.Status).toBe('Active');
350343
expect(outputs.EipConfig).toEqual({ EipFixed: 'TRUE', Eips: expect.any(Array) });
351-
expect(outputs.Layers).toEqual([
352-
{
353-
LayerName: layerInputs.name,
354-
LayerVersion: expect.any(Number),
355-
CompatibleRuntimes: layerInputs.runtimes,
356-
Description: layerInputs.description,
357-
LicenseInfo: '',
358-
AddTime: expect.any(String),
359-
Status: 'Active',
360-
Src: 'Default',
361-
},
362-
]);
344+
345+
expect(outputs.Layers[0].LayerName).toBe(layerInputs.name);
346+
expect(outputs.Layers[0].CompatibleRuntimes).toEqual(layerInputs.runtimes);
347+
expect(outputs.Layers[0].Description).toBe(layerInputs.description);
348+
363349
expect(outputs.PublicNetConfig).toEqual({
364350
PublicNetStatus: 'ENABLE',
365351
EipConfig: { EipStatus: 'ENABLE', EipAddress: expect.any(Array) },

src/modules/metrics/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export default class Metrics {
7373
throw new ApiError({
7474
type: 'API_METRICS_getScfMetrics',
7575
message: e.message,
76-
stack: e.stack,
7776
reqId: e.reqId,
7877
code: e.code,
7978
});
@@ -105,7 +104,6 @@ export default class Metrics {
105104
throw new ApiError({
106105
type: 'API_METRICS_getApigwMetrics',
107106
message: e.message,
108-
stack: e.stack,
109107
reqId: e.reqId,
110108
code: e.code,
111109
});
@@ -138,7 +136,6 @@ export default class Metrics {
138136
throw new ApiError({
139137
type: 'API_METRICS_getCustomMetrics',
140138
message: e.message,
141-
stack: e.stack,
142139
reqId: e.reqId,
143140
code: e.code,
144141
});

src/modules/scf/entities/scf.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,25 @@ export default class ScfEntity extends BaseEntity {
5555
});
5656
return Response;
5757
} catch (e) {
58-
if (e.code == 'ResourceNotFound.FunctionName' || e.code == 'ResourceNotFound.Function') {
58+
if (e.code === 'ResourceNotFound.FunctionName' || e.code === 'ResourceNotFound.Function') {
5959
return null;
6060
}
61-
throw new ApiError({
62-
type: 'API_SCF_GetFunction',
63-
message: e.message,
64-
stack: e.stack,
65-
reqId: e.reqId,
66-
code: e.code,
67-
});
61+
if (e.code === 'InvalidParameterValue.FunctionName') {
62+
throw new ApiError({
63+
type: 'API_SCF_GetFunction',
64+
message: `SCF 函数名称命名不符合规则。 只能包含字母、数字、下划线、连字符,以字母开头,以数字或字母结尾,2~60个字符`,
65+
reqId: e.reqId,
66+
code: e.code,
67+
displayMsg: `SCF 函数名称命名不符合规则。 只能包含字母、数字、下划线、连字符,以字母开头,以数字或字母结尾,2~60个字符`,
68+
});
69+
} else {
70+
throw new ApiError({
71+
type: 'API_SCF_GetFunction',
72+
message: e.message,
73+
reqId: e.reqId,
74+
code: e.code,
75+
});
76+
}
6877
}
6978
}
7079

0 commit comments

Comments
 (0)