Skip to content

Commit 1d81680

Browse files
authored
refactor: use AWS SDK v3-style error handling (#3659)
1 parent 5041ef1 commit 1d81680

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

packages/artillery/lib/platform/aws-ecs/legacy/run-cluster.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const {
66
StopTaskCommand,
77
DescribeTaskDefinitionCommand,
88
RegisterTaskDefinitionCommand,
9-
DeregisterTaskDefinitionCommand
9+
DeregisterTaskDefinitionCommand,
10+
InvalidParameterException,
11+
ThrottlingException
1012
} = require('@aws-sdk/client-ecs');
1113
const {
1214
SQSClient,
@@ -15,7 +17,7 @@ const {
1517
ListQueuesCommand,
1618
GetQueueAttributesCommand
1719
} = require('@aws-sdk/client-sqs');
18-
const { GetObjectCommand } = require('@aws-sdk/client-s3');
20+
const { GetObjectCommand, NoSuchKey } = require('@aws-sdk/client-s3');
1921
const { IAMClient, GetRoleCommand } = require('@aws-sdk/client-iam');
2022
// Normal debugging for messages, summaries, and errors:
2123
const debug = require('debug')('commands:run-test');
@@ -762,7 +764,7 @@ async function tryRunCluster(scriptPath, options, artilleryReporter) {
762764
debug(context.testId, 'done');
763765
} catch (err) {
764766
debug(err);
765-
if (err.code === 'InvalidParameterException') {
767+
if (err instanceof InvalidParameterException) {
766768
if (
767769
err.message
768770
.toLowerCase()
@@ -1353,7 +1355,7 @@ async function getManifest(context) {
13531355

13541356
return context;
13551357
} catch (err) {
1356-
if (err.code === 'NoSuchKey') {
1358+
if (err instanceof NoSuchKey) {
13571359
throw new TestNotFoundError();
13581360
} else {
13591361
throw err;
@@ -1662,7 +1664,7 @@ async function ecsRunTask(context) {
16621664
throw new Error('Not enough ECS capacity');
16631665
}
16641666
} catch (runErr) {
1665-
if (runErr.code === 'ThrottlingException') {
1667+
if (runErr instanceof ThrottlingException) {
16661668
artillery.log('ThrottlingException returned from ECS, retrying');
16671669
await sleep(2000 * retries);
16681670
debug('runTask throttled, retrying');

packages/artillery/lib/platform/aws-lambda/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const {
1414
GetFunctionConfigurationCommand,
1515
InvokeCommand,
1616
CreateFunctionCommand,
17-
DeleteFunctionCommand
17+
DeleteFunctionCommand,
18+
ResourceConflictException,
19+
ResourceNotFoundException
1820
} = require('@aws-sdk/client-lambda');
1921
const { PutObjectCommand } = require('@aws-sdk/client-s3');
2022
const { SQSClient, DeleteQueueCommand } = require('@aws-sdk/client-sqs');
@@ -623,7 +625,7 @@ class PlatformLambda {
623625
});
624626
return;
625627
} catch (err) {
626-
if (err.code === 'ResourceConflictException') {
628+
if (err instanceof ResourceConflictException) {
627629
debug(
628630
'Lambda function with this configuration already exists. Using existing function.'
629631
);
@@ -649,7 +651,7 @@ class PlatformLambda {
649651

650652
return res;
651653
} catch (err) {
652-
if (err.name === 'ResourceNotFoundException') {
654+
if (err instanceof ResourceNotFoundException) {
653655
return null;
654656
}
655657

packages/artillery/lib/platform/aws/aws-ensure-s3-bucket-exists.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const debug = require('debug')('util:aws:ensureS3BucketExists');
77
const {
88
S3Client,
99
PutBucketLifecycleConfigurationCommand,
10-
CreateBucketCommand
10+
CreateBucketCommand,
11+
NoSuchBucket
1112
} = require('@aws-sdk/client-s3');
1213

1314
const getAWSAccountId = require('./aws-get-account-id');
@@ -57,7 +58,7 @@ module.exports = async function ensureS3BucketExists(
5758
try {
5859
location = await getBucketRegion(bucketName);
5960
} catch (err) {
60-
if (err.name === 'NoSuchBucket') {
61+
if (err instanceof NoSuchBucket) {
6162
await s3.send(new CreateBucketCommand({ Bucket: bucketName }));
6263
} else {
6364
throw err;

0 commit comments

Comments
 (0)