-
-
Notifications
You must be signed in to change notification settings - Fork 797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
200 response status code becomes 204 when no response body is set #1257
Comments
Hi @cdubz, did you ever resolve this issue? We are experiencing the same thing... |
@reubenporterjisc I did not -- in fact I forgot all about this. I'm dealing with few enough consumers that we were able to easily adapt and modify them to expect a |
I just ran into this and was very surprised by it. I was returning a simple number as a count in the response for pagination purposes. I could return any size, but started getting mysterious 204s with the body stripped out when I tried to return the number 0. I'm guessing it's just due to a bad falsey check somewhere? To me, a 200 with a response of "0" is different than a 204 with no response body and one should not be converted to the other. |
@aardvarkk I think that’s worth a separate issue. Does sound like a bug worth fixing. |
@cdubz Well... the problem was definitely a bad falsey check. In my code, as it turns out, hah! I had a little helper function before returning the response that was trying to be helpful and ended up casting too wide a net for determining whether responses were empty. I have confirmed that |
@aardvarkk quick question if you want to return a 200 OK response with no body with |
@ky-cheng In my case, it was my fault that I was returning 204s instead of 200s, so I can't speak to how to address the larger issue here. Could you just manually override the status code in the response? |
Yeah I set response.statusCode to 200 with no body but serverless offline seems to auto change the status code to 204 when there is no body so I am not sure what I can do |
I have similar issues with local test for CORS / http OPTIONS call that is expected to return 200 but it's modified to be 204. Started after updating serverless to v3 and serverless-offline to latest 8.3.1. Previously empty 200 came through as expected. |
@cdubz would you mind opening this issue again since you have given the perfect reproduction example in your original post already. Perhaps Serverless offline should only change status code to 204 when the body is empty and no status code supplied. |
Sure. I don’t think we ever got a maintainer in this chain to confirm this as an acceptable behavior so re-opening seems reasonable. |
Agree. I think the main point is that it behaves differently to how for example an AWS lambda function would. The same code would return 200 OK when deployed but return 204 No Content from serverless offline when statusCode 200 is set with no body return |
this was introduced by bumping |
Any updates here? I unfortunately spent quite a bit of time troubleshooting my controller code before I luckily found this issue. |
fixed in v12.0.2 |
Bug Report
Current Behavior
After upgrading to v8.0.0 and when setting
response.statusCode
to200
and not setting a body, the actual response status code from serverless-offline is changed to204
. Adding a body to response works around the issue.Sample Code
Expected behavior/code
Response should have an empty body and a
200
status code.Environment
serverless
version: v2.52.1serverless-offline
version: v8.0.0node.js
version: v12.21.0OS
: macOS 11.4Additional context/Screenshots
This behavior differs from v7.1.0 (which maintains the
200
status code in the example) but does not seem to be specifically documented anywhere. It appears this is somehow related to the dependency updates in ed06c2d.In my case I noticed this with a
PUT
request response where204
surely would be a better status code when no body is present but the enforced change that now occurs is surprising and seems worth a mention in release notes if nothing else.The text was updated successfully, but these errors were encountered: