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

Unhandled Promise Rejection on ALB event #678

Open
repl-ullas-ml opened this issue Apr 23, 2024 · 1 comment
Open

Unhandled Promise Rejection on ALB event #678

repl-ullas-ml opened this issue Apr 23, 2024 · 1 comment

Comments

@repl-ullas-ml
Copy link

repl-ullas-ml commented Apr 23, 2024

Given an ALB event with multiValueQueryStringParameters but one of the value fails decodeURIComponent , the promise isnt handled at all. Expectation is that it should return an error and consumers treat that error

path: getPathWithQueryStringUseUnescapeParams({ event })

query[formattedKey] = event.multiValueQueryStringParameters[key].map(value => decodeUrlencoded(value))

The below test wont even report the failure since the promise is left unhandled

  test('serverlessExpressInstance should throw', async () => {
    const multiValueQueryStringParameters = { etype: ['odp'], passurl: ['/category/'], template: ['../../../../../../../../../etc/passwd%%0000.html'] }

    const event = makeEvent({
      eventSourceName: 'alb',
      path: '/',
      httpMethod: 'GET',
      multiValueQueryStringParameters
    })
    await expect(serverlessExpressInstance(event)).toThrow('some')
  })

Screenshot 2024-04-23 at 11 34 20 AM

@brettstack
Copy link
Collaborator

Thanks for the report. Serverless Express catches errors and returns to a response to the event source with the error in a format expected by the event source. For example, API Gateway expects a statusCode so it returns 500 along with the error. This is usually what you want, since if the Lambda throws an error, API Gateway returns a different error to the client. See:

https://github.com/CodeGenieApp/serverless-express/blob/mainline/src/configure.js#L72-L95 which catches the error, and

https://github.com/CodeGenieApp/serverless-express/blob/mainline/src/transport.js#L62-L80 which determines how to respond. Note line 63 ALB is included in the list of services that will include a response format rather than throwing the error.

If you really want to throw an error, you can do something like const response = await serverlessExpressInstance(event) and inspect it for a 500, and then throw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants