Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle network errors in Lambda client #100

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dist/aws.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/aws.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1 change: 1 addition & 0 deletions dist/aws.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/event-bridge.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/event-bridge.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1 change: 1 addition & 0 deletions dist/event-bridge.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/index.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1 change: 1 addition & 0 deletions dist/index.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/kinesis.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/kinesis.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1 change: 1 addition & 0 deletions dist/kinesis.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/kms.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/kms.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1 change: 1 addition & 0 deletions dist/kms.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/lambda.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/lambda.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1 change: 1 addition & 0 deletions dist/lambda.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/s3.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/s3.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1 change: 1 addition & 0 deletions dist/s3.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/secrets-manager.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/secrets-manager.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1 change: 1 addition & 0 deletions dist/secrets-manager.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/signature.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/signature.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/sqs.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/sqs.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1 change: 1 addition & 0 deletions dist/sqs.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/ssm.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/ssm.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1 change: 1 addition & 0 deletions dist/ssm.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,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'
Loading