From a0579c90dbcc2677ef690d3149c1a28e3e39a73b Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 15 Mar 2020 09:26:44 +0000 Subject: [PATCH] APIHandler: return HTTP/404 when non existing API methods are invoked Before this change, invoking a non existing API method would return an HTTP/200 response with a JSON payload {"code":3,"message":"no such function"}. This commit changes the HTTP status code to 404, leaving the payload as-is. Before: curl --verbose "http://localhost:9001/api/1/notExisting?apikey=ABCDEF" < HTTP/1.1 200 OK < X-Powered-By: Express [...] {"code":3,"message":"no such function","data":null} After: curl --verbose "http://localhost:9001/api/1/notExisting?apikey=ABCDEF" < HTTP/1.1 404 OK < X-Powered-By: Express [...] {"code":3,"message":"no such function","data":null} Fixes #3546. --- src/node/handler/APIHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js index 3898daaf5..cd3258252 100644 --- a/src/node/handler/APIHandler.js +++ b/src/node/handler/APIHandler.js @@ -160,7 +160,7 @@ exports.handle = async function(apiVersion, functionName, fields, req, res) // say goodbye if this is an unknown function if (!(functionName in version[apiVersion])) { - // no status code?! + res.statusCode = 404; res.send({code: 3, message: "no such function", data: null}); return; }