1
votes

Trying to change http status code from an openWhisk web action through api connect

here's my openWhisk action :

function main() {
  return {
    statusCode: 400
  }
}

and connected to an api endpoint /secure

so hitting /secure always returns a 200 instead of 400 and the action's output is added to the response payload.

what could I've done wrong?

1
Have you created the action as a web action? - markusthoemmes
@markusthoemmes Yes, I can't use it in the api connect if its not a web action - Evan Lévesque

1 Answers

2
votes

Create an action with following code:

function main(){
  return ({
        headers: {
          'Content-Type': 'application/json'
        },
        statusCode: 200,
        body: new Buffer(JSON.stringify("Hello World")).toString('base64')
      });
};

Call it as a web action with http as extension. To know more about context extension, read here if you haven't already.

In this case if you change the status code from 200 to 400 you will see the difference. If I am not wrong, you need to include header in the return block.