Skip to content

Commit 5801f43

Browse files
committed
Address review comments
1 parent 2dffb63 commit 5801f43

File tree

3 files changed

+5
-22
lines changed

3 files changed

+5
-22
lines changed

lambdas/api-handler/src/handlers/__tests__/get-letter-data.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { makeApiGwEvent } from './utils/test-utils';
1818
import { ValidationError } from '../../errors';
1919
import * as errors from '../../contracts/errors';
2020
import { createGetLetterDataHandler } from '../get-letter-data';
21-
import { Destination, S3Client } from '@aws-sdk/client-s3';
21+
import { S3Client } from '@aws-sdk/client-s3';
2222
import pino from 'pino';
2323
import { LetterRepository } from '@internal/datastore/src';
2424
import { EnvVars } from '../../config/env';

lambdas/api-handler/src/handlers/__tests__/get_status.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,6 @@ describe('API Lambda handler', () => {
5656
}));
5757
});
5858

59-
it('fails if request ID is absent', async() => {
60-
const event = makeApiGwEvent({path: '/_status',
61-
headers: {'nhsd-supplier-id': 'supplier1', 'nhsd-correlation-id': 'correlationId'}
62-
});
63-
64-
const getLetterDataHandler = createGetStatusHandler(getMockedDeps());
65-
const result = await getLetterDataHandler(event, mockDeep<Context>(), jest.fn());
66-
67-
expect(result).toEqual(expect.objectContaining({
68-
statusCode: 500
69-
}));
70-
});
71-
7259
function getMockedDeps(): jest.Mocked<Deps> {
7360
return {
7461
s3Client: { send: jest.fn()} as unknown as S3Client,

lambdas/api-handler/src/handlers/get-status.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
import { APIGatewayProxyHandler } from "aws-lambda";
22
import { Deps } from "../config/deps";
33
import { ListBucketsCommand, S3Client } from "@aws-sdk/client-s3";
4-
import { validateCommonHeaders } from "../utils/validation";
54
import { mapErrorToResponse } from "../mappers/error-mapper";
65

76
export function createGetStatusHandler(deps: Deps): APIGatewayProxyHandler {
87

98
return async(event) => {
109

11-
const commonHeadersResult = validateCommonHeaders(event.headers, deps);
12-
13-
if (!commonHeadersResult.ok) {
14-
return mapErrorToResponse(commonHeadersResult.error, commonHeadersResult.correlationId, deps.logger);
15-
}
10+
const correlationId = Object.entries(event.headers)
11+
.find(([headerName, _]) => headerName.toLowerCase() === deps.env.APIM_CORRELATION_HEADER)?.[1];
1612

1713
try {
1814
await deps.dbHealthcheck.check();
1915
await s3HealthCheck(deps.s3Client);
2016

2117
deps.logger.info({
2218
description: 'Healthcheck passed',
23-
supplierId: commonHeadersResult.value.supplierId
19+
correlationId
2420
});
2521

2622
return {
2723
statusCode: 200,
2824
body: '{}'
2925
};
3026
} catch (error) {
31-
return mapErrorToResponse(error, commonHeadersResult.value.correlationId, deps.logger);
27+
return mapErrorToResponse(error, correlationId || '', deps.logger);
3228
}
3329
}
3430
}

0 commit comments

Comments
 (0)