Skip to content

Commit

Permalink
introduce a network error class so not all Lambda client errors are t…
Browse files Browse the repository at this point in the history
…reated as AWS errors
  • Loading branch information
ziltodian committed Apr 29, 2024
1 parent db491d4 commit 4cbe995
Show file tree
Hide file tree
Showing 26 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion dist/aws.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aws.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/event-bridge.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/event-bridge.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kinesis.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kinesis.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kms.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kms.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lambda.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lambda.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/s3.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/s3.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/secrets-manager.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/secrets-manager.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/signature.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/signature.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sqs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sqs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ssm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ssm.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export { SQSClient } from './sqs'
export { KinesisClient } from './internal/kinesis'
export { EventBridgeClient } from './internal/event-bridge'
export { LambdaClient, LambdaInvocationError } from './lambda'
export { AWSError, NetworkError} from './internal/error'
10 changes: 10 additions & 0 deletions src/internal/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ export class AWSError extends Error {
}
}
}

export class NetworkError extends Error {
code: number;

constructor(message: string, code: number) {
super(message)
this.name = 'NetworkError'
this.code = code
}
}
6 changes: 5 additions & 1 deletion src/internal/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import encoding from 'k6/encoding'

import { AWSClient } from './client'
import { AWSConfig } from './config'
import { AWSError } from './error'
import { AWSError, NetworkError } from './error'
import { InvalidSignatureError, SignatureV4 } from './signature'
import { AMZ_TARGET_HEADER } from './constants'
import { HTTPHeaders, HTTPMethod, QueryParameterBag } from './http'
Expand Down Expand Up @@ -107,6 +107,10 @@ export class LambdaClient extends AWSClient {
return
}

if (errorCode < 1400 || errorCode >= 1600 ) {
throw new NetworkError(errorMessage, errorCode)
}

const awsError = AWSError.parse(response)
switch (awsError.code) {
case 'AuthorizationHeaderMalformed':
Expand Down
1 change: 1 addition & 0 deletions src/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export {
LambdaInvocationError,
LambdaClient
} from './internal/lambda'
export { AWSError, NetworkError} from './internal/error'

0 comments on commit 4cbe995

Please sign in to comment.