Skip to content

Commit 7c5175e

Browse files
authored
fix: make cos error convert more robust, fix trigger base (#186)
* fix: make cos error convert more robust * fix: add back the token in trigger base
1 parent 9fe81d6 commit 7c5175e

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

__tests__/cos.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ describe('Cos', () => {
7070
};
7171
const cos = new Cos(credentials, process.env.REGION);
7272

73+
test('should deploy Cos fail', async () => {
74+
try {
75+
const res = await cos.deploy({ ...inputs, bucket: '1234567890' });
76+
expect(res).toBe(undefined);
77+
} catch (err) {
78+
console.log(err);
79+
expect(err.code).toBe('Error');
80+
}
81+
});
82+
7383
test('should deploy Cos success', async () => {
7484
const res = await cos.deploy(inputs);
7585
await sleep(1000);

src/modules/cos/index.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,26 @@ import fs from 'fs';
3535
import { traverseDirSync } from '../../utils';
3636
import { ApiTypeError, ApiError } from '../../utils/error';
3737

38-
/** 将 Cos error 转为统一的形式 */
39-
function convertCosError(err: {
40-
error: {
41-
Code: string;
42-
Message: string;
43-
Stack: string;
44-
RequestId: string;
38+
interface CosError {
39+
error?: {
40+
Code?: string;
41+
Message?: string;
42+
Stack?: string;
43+
RequestId?: string;
4544
};
46-
stack: string;
47-
}) {
45+
code?: string;
46+
message?: string;
47+
stack?: string;
48+
requestId?: string;
49+
}
50+
51+
/** 将 Cos error 转为统一的形式 */
52+
function convertCosError(err: CosError) {
4853
const e = {
49-
code: err.error.Code,
50-
message: err.error.Message,
51-
stack: err.stack ?? err.error.Stack,
52-
reqId: err.error.RequestId,
54+
code: err?.error?.Code ?? err.code!,
55+
message: err?.error?.Message ?? err.message!,
56+
stack: err?.stack ?? err?.error?.Stack!,
57+
reqId: err?.error?.RequestId ?? err.requestId!,
5358
};
5459
return e;
5560
}

src/modules/triggers/base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default abstract class BaseTrigger<P = TriggerInputsParams> {
2727
ServiceType: serviceType,
2828
SecretId: credentials.SecretId!,
2929
SecretKey: credentials.SecretKey!,
30+
Token: credentials.Token,
3031
});
3132
}
3233
}

0 commit comments

Comments
 (0)