All files / handlers/api handler.ts

87.5% Statements 14/16
33.33% Branches 2/6
100% Functions 1/1
86.66% Lines 13/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45  1x 1x       1x   1x       6x   6x 6x   6x           6x     6x   6x   6x         6x                  
/* eslint-disable */
import { dispatch } from '../api/router';
import { getLogger } from '../../common/logger';
import { LambdaEvent } from '../../dto/image.dto';
import { APIGatewayProxyResultV2, Context } from 'aws-lambda';
 
const logger = getLogger('APIHandler');
 
export const handler = async (
  event: LambdaEvent,
  context: Context
): Promise<APIGatewayProxyResultV2> => {
  const requestId = context.awsRequestId;
 
  const method = event.requestContext?.http?.method || event.httpMethod;
  const path = event.rawPath || event.resource;
 
  logger.info('Request received', {
    requestId,
    method,
    path,
  });
 
  try {
    // Attach requestId to event for downstream use
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    (event as any).requestId = requestId;
 
    const response = await dispatch(event);
 
    logger.info('Request completed', {
      requestId,
      statusCode: response.statusCode,
    });
 
    return response;
  } catch (error) {
    logger.error('Request failed', {
      requestId,
      error: error instanceof Error ? error.message : String(error),
    });
    throw error;
  }
};