From aaf136d570cc1ee6a3546ee78542e03b01c03257 Mon Sep 17 00:00:00 2001 From: Rob Beal Date: Wed, 15 Nov 2023 14:42:00 +0000 Subject: [PATCH] fix: don't throw error for non http event --- .../http-event-normalizer/__tests__/index.js | 16 ++++------------ packages/http-event-normalizer/index.js | 12 ------------ 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/packages/http-event-normalizer/__tests__/index.js b/packages/http-event-normalizer/__tests__/index.js index 07215fd66..e9c972995 100644 --- a/packages/http-event-normalizer/__tests__/index.js +++ b/packages/http-event-normalizer/__tests__/index.js @@ -7,30 +7,22 @@ const context = { getRemainingTimeInMillis: () => 1000 } -test('It should throw error when invalid version', async (t) => { +test('It should not throw error when invalid version', async (t) => { const event = { version: '3.0' } const handler = middy((event) => event).use(httpEventNormalizer()) - try { - await handler(event, context) - } catch (e) { - t.is(e.message, 'Unknown http event format') - } + t.notThrows(async () => await handler(event, context)) }) -test('It should do nothing if not HTTP event', async (t) => { +test('It should not error if not an HTTP event', async (t) => { const event = { source: 's3' } const handler = middy((event) => event).use(httpEventNormalizer()) - try { - await handler(event, context) - } catch (e) { - t.is(e.message, 'Unknown http event format') - } + t.notThrows(async () => await handler(event, context)) }) test('It should default queryStringParameters with REST API', async (t) => { diff --git a/packages/http-event-normalizer/index.js b/packages/http-event-normalizer/index.js index 9b18e3c17..0c437c729 100644 --- a/packages/http-event-normalizer/index.js +++ b/packages/http-event-normalizer/index.js @@ -3,12 +3,6 @@ const httpEventNormalizerMiddleware = () => { const { event } = request const version = pickVersion(event) - const isHttpEvent = isVersionHttpEvent[version]?.(event) - if (!isHttpEvent) { - throw new Error('Unknown http event format', { - cause: { package: '@middy/http-event-normalizer' } - }) - } // VPC Lattice is an http event, however uses a different notation // - query_string_parameters // - is_base64_encoded @@ -35,10 +29,4 @@ const pickVersion = (event) => { return event.version ?? (event.method ? 'vpc' : '1.0') } -const isVersionHttpEvent = { - '1.0': (event) => typeof event.httpMethod !== 'undefined', - '2.0': (event) => typeof event.requestContext.http.method !== 'undefined', - vpc: (event) => typeof event.method !== 'undefined' -} - export default httpEventNormalizerMiddleware