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

[Good first issue] better error message when body is undefined #91

Closed
swyxio opened this issue Dec 29, 2018 · 3 comments
Closed

[Good first issue] better error message when body is undefined #91

swyxio opened this issue Dec 29, 2018 · 3 comments

Comments

@swyxio
Copy link
Contributor

swyxio commented Dec 29, 2018

splitting out @waynehoover's issue from here: #43 (comment)

when you do this:

exports.handler = async function(event, context) {
    let body = parse(event.body)
    await doSomeAsyncWorkHere();
    return {
      statusCode: 301,
		// oops no body
    }
}

you get this:

(node:26997) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string or Buffer. Received type undefined
    at write_ (_http_outgoing.js:607:11)
    at ServerResponse.write (_http_outgoing.js:579:10)
    at callback (/Users/.../node_modules/netlify-lambda/lib/serve.js:26:14)
    at /Users/.../node_modules/netlify-lambda/lib/serve.js:41:21
    at process.internalTickCallback (internal/process/next_tick.js:77:7)
(node:26997) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:26997) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Hash: ec967454cf2cf833f214

we should basically insert an undefined check here: https://github.com/netlify/netlify-lambda/blob/master/lib/serve.js#L29 and serve a friendly warning

should also thinking about other forms of validation

@swyxio
Copy link
Contributor Author

swyxio commented Dec 29, 2018

pr welcome

@danew
Copy link

danew commented Feb 3, 2019

I ran into this issue earlier today as well.
From my perspective, I think the response body should be optional.

What do you think?

@swyxio
Copy link
Contributor Author

swyxio commented Feb 3, 2019

@swyxio swyxio closed this as completed Feb 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants