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.
pull/3726/head
John McLear 2020-03-15 09:26:44 +00:00
parent 0d61d6bb13
commit a0579c90db
1 changed files with 1 additions and 1 deletions

View File

@ -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;
}