Commit 68baa2ac authored by Tim Niemeyer's avatar Tim Niemeyer Committed by Jan-Tarek Butt

api: rework router error handling

Signed-off-by: default avatarTim Niemeyer <tim.niemeyer@mastersword.de>
parent c352dba1
......@@ -70,19 +70,36 @@
}
private function router() {
if($this->get_request_method() == "GET" && (isset($this->_request['router_id']) || isset($this->_request['hostname']))) {
if ($this->get_request_method() != "GET") {
$this->error_code = 3;
$this->error_message = "Wrong method";
$this->response($this->finishxml(), 405);
return false;
}
if (isset($this->_request['router_id']) || isset($this->_request['hostname']))) {
$this->_request['router_id'] = (isset($this->_request['router_id'])) ? $this->_request['router_id'] : false;
$this->_request['hostname'] = (isset($this->_request['hostname'])) ? $this->_request['hostname'] : false;
$router = new Router((int)$this->_request['router_id'], false, $this->_request['hostname']);
if(!$router->fetch()) {
$this->error_code = 1;
$this->error_message = "Router not found";
$this->response($this->finishxml(), 404);
} else {
$domxmldata = $router->getDomXMLElement($this->domxml);
$this->response($this->finishxml($domxmldata), 200);
}
}
if (!$router) {
$this->error_code = 2;
$this->error_message = "Wrong request";
$this->response($this->finishxml(), 400);
return false;
}
if (!$router->fetch()) {
$this->error_code = 1;
$this->error_message = "Router not found";
$this->response($this->finishxml(), 404);
return false;
}
$domxmldata = $router->getDomXMLElement($this->domxml);
$this->response($this->finishxml($domxmldata), 200);
return true;
}
private function routerlist() {
......@@ -449,4 +466,4 @@
$api = new API;
$api->processApi();
?>
\ No newline at end of file
?>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment