REST endpoints now return specific HTTP codes on failure (fix #4278)

This commit is contained in:
Alfredo Cardigliano 2020-08-20 11:45:17 +02:00
parent 745b3b52d3
commit ba2e44ddc6
37 changed files with 141 additions and 228 deletions

View file

@ -18,8 +18,6 @@ local rest_utils = require("rest_utils")
-- NOTE: in case of invalid login, no error is returned but redirected to login
--
sendHTTPHeader('application/json')
local rc = rest_utils.consts.success.ok
local res = {}
@ -27,7 +25,7 @@ local ifid = _GET["ifid"]
if isEmptyString(ifid) then
rc = rest_utils.consts.err.invalid_interface
print(rest_utils.rc(rc))
rest_utils.answer(rc)
return
end
@ -49,4 +47,4 @@ end
res.addresses = addresses;
print(rest_utils.rc(rc, res))
rest_utils.answer(rc, res)

View file

@ -26,8 +26,6 @@ local rest_utils = require("rest_utils")
-- NOTE: in case of invalid login, no error is returned but redirected to login
--
sendHTTPHeader('application/json')
local rc = rest_utils.consts.success.ok
local res = {}
@ -36,7 +34,7 @@ local iffilter = _GET["iffilter"]
if isEmptyString(ifid) and isEmptyString(iffilter) then
rc = rest_utils.consts.err.invalid_interface
print(rest_utils.rc(rc))
rest_utils.answer(rc)
return
end
@ -259,4 +257,4 @@ else
res = dumpInterfaceStats(ifid)
end
print(rest_utils.rc(rc, res))
rest_utils.answer(rc, res)

View file

@ -16,8 +16,6 @@ local dscp_consts = require "dscp_consts"
-- NOTE: in case of invalid login, no error is returned but redirected to login
--
sendHTTPContentTypeHeader('text/html')
local rc = rest_utils.consts.success.ok
local res = {}
@ -25,7 +23,7 @@ local ifid = _GET["ifid"]
if isEmptyString(ifid) then
rc = rest_utils.consts.err.invalid_interface
print(rest_utils.rc(rc))
rest_utils.answer(rc)
return
end
@ -34,7 +32,7 @@ interface.select(ifid)
local stats = interface.getStats()
if stats == nil then
print(rest_utils.rc(rest_utils.consts.err.internal_error))
rest_utils.answer(rest_utils.consts.err.internal_error)
return
end
@ -45,4 +43,4 @@ for key, value in pairsByKeys(stats.dscp, asc) do
}
end
print(rest_utils.rc(rc, res))
rest_utils.answer(rc, res)

View file

@ -15,8 +15,6 @@ local rest_utils = require("rest_utils")
-- NOTE: in case of invalid login, no error is returned but redirected to login
--
sendHTTPContentTypeHeader('text/html')
local rc = rest_utils.consts.success.ok
local res = {}
@ -27,7 +25,7 @@ local ndpi_category = _GET["ndpi_category"]
if isEmptyString(ifid) then
rc = rest_utils.consts.err.invalid_interface
print(rest_utils.rc(rc))
rest_utils.answer(rc)
return
end
@ -61,12 +59,12 @@ if ndpistats_mode == "sinceStartup" then
elseif ndpistats_mode == "count" then
stats = interface.getnDPIFlowsCount()
else
print(rest_utils.rc(rest_utils.consts.err.invalid_args))
rest_utils.answer(rest_utils.consts.err.invalid_args)
return
end
if stats == nil then
print(rest_utils.rc(rest_utils.consts.err.internal_error))
rest_utils.answer(rest_utils.consts.err.internal_error)
return
end
@ -106,7 +104,7 @@ if(ndpistats_mode == "count") then
}
end
print(rest_utils.rc(rc, res))
rest_utils.answer(rc, res)
return
end
@ -152,4 +150,4 @@ if(accumulate < tot) then
}
end
print(rest_utils.rc(rc, res))
rest_utils.answer(rc, res)