Added return data to api request debugging

This commit is contained in:
Frank Schubert
2022-09-16 13:58:09 +02:00
parent 2b9de506ca
commit 0d6abb53d5

View File

@@ -77,6 +77,7 @@ class mfBaseApicontroller {
}
private function logRequest() {
$this->requestLog->debug("==================================================================");
$this->requestLog->debug("new API request for ".$_SERVER['REQUEST_URI']);
$this->requestLogstr = "";
foreach($_GET as $key => $value) {
@@ -162,7 +163,7 @@ class mfBaseApicontroller {
private function getPostRequest() {
$body = $this->getRequestBody();
if(is_array($body)) {
if(!is_string($body) && is_array($body)) {
// request is parsed already ($_POST)
return $body;
}
@@ -179,7 +180,7 @@ class mfBaseApicontroller {
}
private function getRequestBody() {
if($_SERVER["CONTENT_TYPE"] == "application/json") {
if(strtolower($this->headers['content-type']) == "application/json") {
$request_body = file_get_contents('php://input');
return $request_body;
}
@@ -208,6 +209,17 @@ class mfBaseApicontroller {
if($_SERVER["SERVER_PROTOCOL"]) {
$proto = $_SERVER["SERVER_PROTOCOL"];
}
$this->requestLog->debug("$proto $code $status");
$this->requestLog->debug("status $status, result: ");
foreach($data as $key => $res) {
if(is_array($res)) {
$this->requestLog->debug($key.": (".count($res).")");
} else {
$this->requestLog->debug($key.": ".$res);
}
}
header("$proto $code $status");
header("Content-type: application/json");
//http_response_code($code);
@@ -235,6 +247,19 @@ class mfBaseApicontroller {
if($_SERVER["SERVER_PROTOCOL"]) {
$proto = $_SERVER["SERVER_PROTOCOL"];
}
$log = new mfLog_File();
$log->init(BASEDIR."/var/log/api-request.log");
$log->debug("$proto $code $status");
$log->debug("status $status, result: ");
foreach($data as $key => $res) {
if(is_array($res)) {
$log->debug($key.": (".count($res).")");
} else {
$log->debug($key.": ".$res);
}
}
header("$proto $code $status");
header("Content-type: application/json");
//http_response_code($code);
@@ -361,7 +386,7 @@ class mfBaseApicontroller {
}
// no route found
$this->return(mfResponse::BadRequest());
$this->return(mfResponse::BadRequest(["message" => "Invalid endpoint"]));
exit;
}