Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't throw error for non http event #1133

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions packages/http-event-normalizer/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
12 changes: 0 additions & 12 deletions packages/http-event-normalizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Loading