openfaas-incubator / node8-express-template

Node.js 8 template for OpenFaaS with HTTP via Express.js
MIT License
15 stars 18 forks source link

Status code is lost and 200 is always returned #1

Closed beverlycodes closed 5 years ago

beverlycodes commented 6 years ago

Setting a status code via context or letting the template itself handle an error both result in a 200 response code being sent to the original invoker. May be a bug in of-watchdog or even further up the chain rather than this template since I originally tried with a custom template and got the same result. I can assert that a non-200 status code is going out, but the original invoker (faas-cli or the faas-netes UI) reports a 200. The error body is sent, it just comes through with a 200 status code instead of 500 or whatever custom code was used.

alexellis commented 6 years ago

@ryanfields we have not observed that behaviour.

Please can you give a clear worked example?

viveksyngh commented 6 years ago

I have tested this on docker swarm on my local with below function code.

"use strict"

module.exports = (event, context) => {
    let err;
    const result =             {
        status: "You said: " + JSON.stringify(event.body)
    };

    if(event.body === "fail" ){
        context
            .status(400)
            .succeed(result);
    } else {
        context
            .status(200)
            .succeed(result);
    }
}

It is reponsing with correct response codes.

viveksyngh commented 6 years ago

@ryanfields could you please provide a code snippet of your function? We will try to reproduce the same behavior.

With our code snippet, we can see correct response code being returned by the function.

alexellis commented 5 years ago

Not an issue.