Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

How to explicitly handle lambda request? #35

Open
mkliu opened this issue May 2, 2021 · 3 comments
Open

How to explicitly handle lambda request? #35

mkliu opened this issue May 2, 2021 · 3 comments

Comments

@mkliu
Copy link

mkliu commented May 2, 2021

So i know i could do

module.exports.googleHandler = googleActionApp

But i want to explicitly handle the call myself, so i could do something before the response is sent. Something like this:

module.exports.googleHandler = async function(event: any, context: any, callback: any) {
  if (!googleActionApp) {
      googleActionApp = createApp()
  }
  (googleActionApp as LambdaHandler)(event, context, callback)
}

I could see my handler's first method is starting to get called, but it always exits pre-maturally. Any suggestions?

Basically i want to flush logging before exit, if anyone know how to have a response middleware, it'll do the job too.

@mkliu
Copy link
Author

mkliu commented May 2, 2021

I looked at the implementation and trying to do it this way:

async function(event: any, context: any, callback: any) {
  if (!googleActionApp) {
      googleActionApp = createApp()
  }
  await googleActionApp.frameworks.lambda.handle(googleActionApp.handler)(event, context, (err, res) => {
    console.log('googleActionApp callback', err, res)
    return res;
  })
}

The request is returned by with this error from google test console
Invalid response from webhook: Failed to translate JSON to ExecuteHttpResponse..

@mkliu
Copy link
Author

mkliu commented May 2, 2021

nvm, find the solution myself, for anyone who's interested, this would work:

async function(event: any, context: any, callback: any) {
  if (!googleActionApp) {
      googleActionApp = createApp()
  }
  let response
  await googleActionApp.frameworks.lambda.handle(googleActionApp.handler)(event, context, (err, res) => {
    console.log('googleActionApp callback', err, res)
    response = res;
  })
  return response
}

@Fleker
Copy link
Member

Fleker commented May 4, 2021

Seems like you may be interested in a postware method to compliment the middleware method.

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

No branches or pull requests

2 participants