File tree Expand file tree Collapse file tree 3 files changed +5
-22
lines changed
lambdas/api-handler/src/handlers Expand file tree Collapse file tree 3 files changed +5
-22
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import { makeApiGwEvent } from './utils/test-utils';
1818import { ValidationError } from '../../errors' ;
1919import * as errors from '../../contracts/errors' ;
2020import { createGetLetterDataHandler } from '../get-letter-data' ;
21- import { Destination , S3Client } from '@aws-sdk/client-s3' ;
21+ import { S3Client } from '@aws-sdk/client-s3' ;
2222import pino from 'pino' ;
2323import { LetterRepository } from '@internal/datastore/src' ;
2424import { EnvVars } from '../../config/env' ;
Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff line change 11import { APIGatewayProxyHandler } from "aws-lambda" ;
22import { Deps } from "../config/deps" ;
33import { ListBucketsCommand , S3Client } from "@aws-sdk/client-s3" ;
4- import { validateCommonHeaders } from "../utils/validation" ;
54import { mapErrorToResponse } from "../mappers/error-mapper" ;
65
76export 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}
You can’t perform that action at this time.
0 commit comments