8000 Protect for null lambda response types. (#551) · DataDog/datadog-lambda-js@9c025c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c025c9

Browse files
authored
Protect for null lambda response types. (#551)
1 parent a7a56f1 commit 9c025c9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/index.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,23 @@ describe("datadog", () => {
449449
expect(mockedIncrementInvocations).toBeCalledWith(expect.anything(), mockContext);
450450
});
451451

452+
it("doesn't increment batch item failures if its null", async () => {
453+
const lambdaResponse: any = null;
454+
455+
const wrapped = datadog(async () => {
456+
return lambdaResponse;
457+
});
458+
459+
const lambdaResult = await wrapped({}, mockContext, () => {});
460+
461+
expect(lambdaResult).toEqual(lambdaResponse);
462+
463+
expect(mockedIncrementBatchItemFailures).toBeCalledTimes(0);
464+
expect(mockedIncrementInvocations).toBeCalledTimes(1);
465+
466+
expect(mockedIncrementInvocations).toBeCalledWith(expect.anything(), mockContext);
467+
});
468+
452469
it("doesn't increment errors or invocations with config false setting", async () => {
453470
const handlerError: Handler = (event, context, callback) => {
454471
throw Error("Some error");

src/utils/batch-item-failures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export function isBatchItemFailure(lambdaResponse: any): boolean {
22
return (
33
typeof lambdaResponse === "object" &&
4+
lambdaResponse !== null &&
45
"batchItemFailures" in lambdaResponse &&
56
Array.isArray(lambdaResponse.batchItemFailures)
67
);

0 commit comments

Comments
 (0)
0