node10-express-template
node10-express-template copied to clipboard
[WIP] Fix fail method
The following PR will fix an issue where context.fail() did not return custom status codes even though context.status() was called.
Description
I modified the context.succeed() and context.fail() methods to return a default status code of 200 and 500, respectively.
When the callback method (cb) is invoked, it will check which status code to return by checking if it has been defined by the handler (i.e. this.statusCode !== undefined). Otherwise, it will return the default status code mentioned above.
Motivation and Context
- [x] I have raised an issue to propose this change (required)
Which issue(s) this PR fixes
Fixes #4
How Has This Been Tested?
I created a handler with the following snippet and got the expected status code and message.
module.exports = (event, context) => {
context
.status(501)
.fail('An error occurred');
}
Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
Checklist:
- [x] My code follows the code style of this project.
- [x] I've read the CONTRIBUTION guide
- [x] I have signed-off my commits with
git commit -s
I'm wondering if we should package a small unit test using mocha and a dev dependency?
👋 @tuct
👇 ?
Join Slack to connect with the community https://docs.openfaas.com