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

Better error for async middleware #124

Merged
merged 1 commit into from
Aug 9, 2024
Merged

Better error for async middleware #124

merged 1 commit into from
Aug 9, 2024

Conversation

macdonst
Copy link
Contributor

@macdonst macdonst commented Aug 9, 2024

If you accidentally set a synchronous function as one of your middleware steps an error will be thrown.

Oops, something went wrong
TypeError: Cannot destructure property 'content-type' of 'state.headers' as it is undefined.
    at Object.api (file:///Users/simonmacdonald/Developer/macdonst/js-quiz/node_modules/@enhance/arc-plugin-enhance/src/http/any-catchall/router.mjs:236:31)
    at async lambda (/Users/simonmacdonald/Developer/macdonst/js-quiz/node_modules/@architect/functions/src/http/index.js:37:22)

Which is not very helpful.

With this change the error changes to:

Lambda error
Error: Error: Middleware function "isAdmin" for "/admin/" is not an async function. All middleware functions must be "async".
Lambda: @http any /*
Source: /Users/simonmacdonald/Developer/macdonst/js-quiz/node_modules/@enhance/arc-plugin-enhance/src/http/any-catchall
: Middleware function "isAdmin" for "/admin/" is not an async function. All middleware functions must be "async".

Stack trace:
Error: Middleware function "isAdmin" for "/admin/" is not an async function. All middleware functions must be "async".,    at file:///Users/simonmacdonald/Developer/macdonst/js-quiz/node_modules/@enhance/arc-plugin-enhance/src/http/any-catchall/router.mjs:95:17,    at Array.forEach (),    at Object.api (file:///Users/simonmacdonald/Developer/macdonst/js-quiz/node_modules/@enhance/arc-plugin-enhance/src/http/any-catchall/router.mjs:93:14),    at async lambda (/Users/simonmacdonald/Developer/macdonst/js-quiz/node_modules/@architect/functions/src/http/index.js:37:22)

So more descriptive and should help folks find their error quickly.

@macdonst macdonst requested a review from brianleroux August 9, 2024 14:36
@macdonst macdonst merged commit b1268aa into main Aug 9, 2024
21 checks passed
@macdonst macdonst deleted the async-check branch August 9, 2024 16:29
@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant