Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6f47b28

Browse files
chore: address feedbacks
Co-authored-by: Trivikram Kamat <[email protected]>
1 parent 3cfacd1 commit 6f47b28

File tree

1 file changed

+8
-8
lines changed
  • packages/middleware-recursion-detection/src

1 file changed

+8
-8
lines changed

packages/middleware-recursion-detection/src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ interface PreviouslyResolved {
2222
* Inject to trace ID to request header to detect recursion invocation in Lambda.
2323
* @internal
2424
*/
25-
export function recursionDetectionMiddleware(options: PreviouslyResolved): BuildMiddleware<any, any> {
26-
return <Output extends MetadataBearer>(next: BuildHandler<any, Output>): BuildHandler<any, Output> =>
25+
const recursionDetectionMiddleware = (options: PreviouslyResolved): BuildMiddleware<any, any> =>
26+
(next: BuildHandler<any, Output>): BuildHandler<any, Output> =>
2727
async (args: BuildHandlerArguments<any>): Promise<BuildHandlerOutput<Output>> => {
2828
const { request } = args;
29-
if (!HttpRequest.isInstance(request) || options.runtime !== "node") {
29+
if (
30+
!HttpRequest.isInstance(request) ||
31+
options.runtime !== "node" ||
32+
request.headers.hasOwnProperty(TRACE_ID_HEADER_NAME)
33+
) {
3034
return next(args);
3135
}
3236

3337
const functionName = process.env[ENV_LAMBDA_FUNCTION_NAME];
3438
const traceId = process.env[ENV_TRACE_ID];
3539
const nonEmptyString = (str: unknown): str is string => typeof str === "string" && str.length > 0;
36-
if (
37-
!request.headers.hasOwnProperty(TRACE_ID_HEADER_NAME) &&
38-
nonEmptyString(functionName) &&
39-
nonEmptyString(traceId)
40-
) {
40+
if (nonEmptyString(functionName) && nonEmptyString(traceId)) {
4141
request.headers[TRACE_ID_HEADER_NAME] = traceId;
4242
}
4343
return next({

0 commit comments

Comments
 (0)