Browse Source

fail better if Feeds.view() data failed encoding to JSON

Andrew Dolgov 9 months ago
parent
commit
215c9f0f88
2 changed files with 10 additions and 1 deletions
  1. 8 1
      classes/feeds.php
  2. 2 0
      errors.php

+ 8 - 1
classes/feeds.php

@@ -563,7 +563,14 @@ class Feeds extends Handler_Protected {
 		// this is parsed by handleRpcJson() on first viewfeed() to set cdm expanded, etc
 		$reply['runtime-info'] = make_runtime_info();
 
-		print json_encode($reply);
+		$reply_json = json_encode($reply);
+
+		if (!$reply_json) {
+		    $reply_json = json_encode(["error" => ["code" => 15,
+                "message" => json_last_error_msg()]]);
+        }
+
+		print $reply_json;
 
 	}
 

+ 2 - 0
errors.php

@@ -38,6 +38,8 @@
 
 	$ERRORS[14] = __("Plugin not found");
 
+	$ERRORS[15] = __("Encoding data as JSON failed");
+
 	if ($_REQUEST['mode'] == 'js') {
 		header("Content-Type: text/javascript; charset=UTF-8");