Browse Source

added apiResponseFormatter function to help with responses to logs

CauseFX 4 years ago
parent
commit
9e3e5f57f9
1 changed files with 14 additions and 0 deletions
  1. 14 0
      api/functions/normal-functions.php

+ 14 - 0
api/functions/normal-functions.php

@@ -585,6 +585,20 @@ trait NormalFunctions
 		return sprintf("%.{$dec}f %s", $bytes / (1024 ** $factor), $size[$factor]);
 	}
 	
+	public function apiResponseFormatter($response)
+	{
+		if (is_array($response)) {
+			return $response;
+		}
+		if (empty($response) || $response == '') {
+			return ['api_response' => 'No data'];
+		}
+		if ($this->json_validator($response)) {
+			return json_decode($response, true);
+		}
+		return ['api_response' => 'No data'];
+	}
+	
 	public function json_validator($data = null)
 	{
 		if (!empty($data)) {