Azure / Azure/azure-functions-host

Status code is ignored when body is missing from response code (Node JS runtime)

Open
#3,191 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

I'm running functions in the Node JS runtime. When returning a response object with status code but without `body` the status code will be ignored and will always return 200.

The following example will return 500 as expected (`body` is passed in the response):
```
module.exports = function (context, req) {
context.res = {
status: 500,
body: "error"
};
context.done();
};
```

So is the following, where response isn't considered an object:
```
module.exports = function (context, req) {
context.res.status = 500;
context.done();
};
```

However, the following example will return **200**:
```
module.exports = function (context, req) {
context.res = {
status: 500
};
context.done();
};
```

Seems like the issue in the following implementation, where it expects to have a `body` property when response is passed as an object: https://github.com/Azure/azure-functions-host/blob/43ad9216b88b4c5329190ff56fad0980641883de/src/WebJobs.Script/Binding/Http/HttpBinding.cs#L104

Thanks,
Benny

Contributor guide

Open the contributing guide

Research direction

Start at src/WebJobs.Script/Binding/Http/HttpBinding.cs around line 104, as linked in the issue, and reproduce the three Node.js response examples. Compare how an object with status but no body is handled; the work is done when that response preserves status 500 instead of returning 200.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, node.js
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.