openfaas-incubator / node10-express-template

Node.js 10 Express Template for OpenFaaS
MIT License
24 stars 26 forks source link

[WIP] Fix fail method #5

Open kturcios opened 5 years ago

kturcios commented 5 years ago

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

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

Checklist:

alexellis commented 5 years ago

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

alexellis commented 5 years ago

πŸ‘‹ @tuct

πŸ‘‡ ?

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