feathers
feathers copied to clipboard
Returning `undefined` from service's method, always get 404 HTTP Status instead of 204
Steps to reproduce
I've created an reproducible repo here: https://github.com/Thammachart/feathersjs-204-issue
- Created the feathersjs Project using
feathers g app, with@feathersjs/cliversion 4.2.4- Choices were Javascript, Yarn, REST API only, Mocha + Assert, No Authentication
- Created Service, in the example repo,
svc1- Choices were A custom service,
svc1,/svc1
- Choices were A custom service,
- Created service's methods for multiple cases, see the link
- Run
yarn start - Using
curl localhost:3030/svc1with multiple flags like-XGET,-XPOST,-XPATCH,-XDELETEto test each case in each service's method
Expected behavior
- Any methods that return
undefinedornullshould response with 204 No Content HTTP Status Code
Actual behavior
- methods returning
undefinedimplicitly or explicitly, response with the 404 Not Found HTTP Status Code, even though the method exists and got to run properly (console.login methods run properly) - methods returning
nullwork as expected - Interesting Note 1: methods returning boolean
falseresponse with 204 No Content HTTP Status Code - Interesting Note 2: methods returning boolean
trueresponse with 2xx HTTP Status Code with content of literaltrue
I don't know if there is underlying convention behind this. I've checked the Docs, FAQ to no avail.
System configuration
Module versions (especially the part that's not working):
@feathersjs/feathers^4.3.11@feathersjs/express^4.3.11- The rest can be seen at this link
NodeJS version: 12.13.1 from nvm
Operating System: Arch Linux, Kernel 5.4.3-arch1-1
Browser Version: curl 7.67.0
Yes, the return value should be null. It's tested at https://github.com/feathersjs/feathers/blob/master/packages/express/test/rest.test.js#L519 (service at https://github.com/feathersjs/feathers/blob/master/packages/express/test/rest.test.js#L467). Not entirely sure where the best place for it would be in the docs.
Ok then,
- what about
undefined? Should it be treated differently thannull? For me, in the context of response payload, there is no difference, andundefinedis easily a pitfall, when you forget to return - what about boolean true/false inconsistency?
Is this behavior still happen ? should we return 'undefined' or 'void' ? only 'null' ?