Correctly set error code for missing SNMP version

This commit is contained in:
Paul Gear
2014-09-27 18:34:23 +10:00
parent 82613f17ee
commit d6245fd6ba

View File

@@ -326,6 +326,7 @@ function list_devices()
function add_device() function add_device()
{ {
// This will add a device using the data passed encoded with json // This will add a device using the data passed encoded with json
// FIXME: Execution flow through this function could be improved
global $config; global $config;
$app = \Slim\Slim::getInstance(); $app = \Slim\Slim::getInstance();
$data = json_decode(file_get_contents('php://input'), true); $data = json_decode(file_get_contents('php://input'), true);
@@ -368,15 +369,17 @@ function add_device()
} }
else else
{ {
$code = 400;
$status = "error";
$message = "You haven't specified an SNMP version to use"; $message = "You haven't specified an SNMP version to use";
} }
$code = 201;
if(empty($message)) if(empty($message))
{ {
require_once("../includes/functions.php"); require_once("../includes/functions.php");
$result = addHost($hostname, $snmpver, $port, $transport, 1); $result = addHost($hostname, $snmpver, $port, $transport, 1);
if($result) if($result)
{ {
$code = 201;
$status = "ok"; $status = "ok";
$message = "Device $hostname has been added successfully"; $message = "Device $hostname has been added successfully";
} }