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

Cannot throw from middleware 'before' #247

Closed
tsmith123 opened this issue Oct 25, 2018 · 1 comment
Closed

Cannot throw from middleware 'before' #247

tsmith123 opened this issue Oct 25, 2018 · 1 comment

Comments

@tsmith123
Copy link

Just trying out Middy and have a small issue with returning early from a before middleware. I'm using Node 8.10 with async.

My middleware looks like this:

const validate = (config) => {
  return ({
    before: async (handler, next) => {
      throw new Error('This is not a booking')
    }
  })
}

This does not return early with an error though I thought it would do. It seems to return to the function and continue executing it instead.

If I change before to after (which is of course not what I want):

const validate = (config) => {
  return ({
    after: async (handler, next) => {
      throw new Error('This is not a booking')
    }
  })
}

then this returns the actual error, I assume because it's the last piece of code that is run.

How can I get the before part to return with an error before the Lambda itself is called?

@willfarrell
Copy link
Member

Can you please re-test this using the v1 branch using node >= v10. CLosing for now, please re-open if necessary.

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

No branches or pull requests

2 participants