Skip to content

Commit

Permalink
Merge pull request #1160 from sharifhh/patch-1
Browse files Browse the repository at this point in the history
Do not throw error if event is not http (http-cors)
  • Loading branch information
willfarrell authored Jan 11, 2024
2 parents 432855f + c72d287 commit ad47810
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
8 changes: 2 additions & 6 deletions packages/http-cors/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,15 +819,11 @@ test('it should set Vary header if present in config', async (t) => {
})
})

test('it should throw when not a http event', async (t) => {
test('it should not throw when not a http event', async (t) => {
const handler = middy((event, context) => {})

handler.use(cors())

const event = {}
try {
await handler(event, context)
} catch (e) {
t.is(e.message, 'Unknown http event format')
}
t.notThrows(async () => await handler(event, context))
})
5 changes: 0 additions & 5 deletions packages/http-cors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ const modifyHeaders = (headers, options, request) => {
const httpMethod = getVersionHttpMethod[request.event.version ?? '1.0']?.(
request.event
)
if (!httpMethod) {
throw new Error('Unknown http event format', {
cause: { package: '@middy/http-cors' }
})
}
if (
httpMethod === 'OPTIONS' &&
options.cacheControl &&
Expand Down

0 comments on commit ad47810

Please sign in to comment.