node10-express-template icon indicating copy to clipboard operation
node10-express-template copied to clipboard

[WIP] Fix fail method

Open kturcios opened this issue 5 years ago • 2 comments

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

kturcios avatar Mar 04 '19 00:03 kturcios

I'm wondering if we should package a small unit test using mocha and a dev dependency?

alexellis avatar Apr 29 '19 21:04 alexellis

👋 @tuct

👇 ?

Join Slack to connect with the community https://docs.openfaas.com

alexellis avatar Apr 29 '19 21:04 alexellis