Skip to content

Handle thrown exceptions consistently with other frameworks #422

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

Closed
anniefu opened this issue Feb 3, 2022 · 2 comments · Fixed by #427
Closed

Handle thrown exceptions consistently with other frameworks #422

anniefu opened this issue Feb 3, 2022 · 2 comments · Fixed by #427
Assignees

Comments

@anniefu
Copy link
Contributor

anniefu commented Feb 3, 2022

There are two scenarios where Node behaves different from most other Functions Frameworks

  1. User throws an exception in their function code
  2. User returns an error in their event-driven function code (HTTP functions don't have return parameters)

Most frameworks will return HTTP status code 500 in both those cases, and hide the exception/error message from the invoker.

Node returns 200 status code and returns the exception/error message in the response body. We should modify node to return 500 and omit the exception/error message from the response body to avoid leaking debug information to the invoker. We should log the message instead.

@grant
Copy link
Contributor

grant commented Feb 3, 2022

Correct. I'm seeing a 200 error being sent in Node.

/**
 * Send "Hello, World!"
 * @param req https://expressjs.com/en/api.html#req
 * @param res https://expressjs.com/en/api.html#res
 */
exports.helloWorld = (req, res) => {
  throw new Error('hi');
  res.send('Hello, World!');
};

Response:

HTTP/1.1 200 OK
X-Google-Status: crash
Content-Type: text/html; charset=utf-8
Content-Length: 2
ETag: W/"2-witfkXg0JglCjW9RssWvTAveakI"
Date: Thu, 03 Feb 2022 20:51:26 GMT
Connection: keep-alive
Keep-Alive: timeout=5

Expected:

HTTP/1.1 500 Internal Server Error
X-Google-Status: crash
Content-Type: text/html; charset=utf-8
Content-Length: 2
ETag: W/"2-witfkXg0JglCjW9RssWvTAveakI"
Date: Thu, 03 Feb 2022 20:48:32 GMT
Connection: keep-alive
Keep-Alive: timeout=5

Location of sending error:

https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/master/src/logger.ts#L46

I believe we can simply do a:

res.status(500);

@grant
Copy link
Contributor

grant commented Feb 7, 2022

May need another pair of eyes to understand the failures / expected result.

@grant grant removed their assignment Feb 24, 2022
@anniefu anniefu linked a pull request Feb 24, 2022 that will close this issue
@anniefu anniefu closed this as completed Feb 24, 2022
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

Successfully merging a pull request may close this issue.

3 participants