]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use JSON_THROW_ON_ERROR instead of custom error handling 32628/head
authorJulius Härtl <jus@bitgrid.net>
Fri, 27 May 2022 12:57:22 +0000 (14:57 +0200)
committerJulius Härtl <jus@bitgrid.net>
Mon, 30 May 2022 17:17:49 +0000 (19:17 +0200)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
lib/public/AppFramework/Http/JSONResponse.php
tests/lib/AppFramework/Http/JSONResponseTest.php

index f4b936435c8a5c0acce6c3640d3284c036f0650b..4870a64afd731fab44bc2267d3981c81f0eb94b3 100644 (file)
@@ -64,13 +64,7 @@ class JSONResponse extends Response {
         * @throws \Exception If data could not get encoded
         */
        public function render() {
-               $response = json_encode($this->data, JSON_HEX_TAG);
-               if ($response === false) {
-                       throw new \Exception(sprintf('Could not json_encode due to invalid ' .
-                               'non UTF-8 characters in the array: %s', var_export($this->data, true)));
-               }
-
-               return $response;
+               return json_encode($this->data, JSON_HEX_TAG | JSON_THROW_ON_ERROR);
        }
 
        /**
index 504876b2d888298b26bcdd84bfd32359f5f62ea4..8c8318eb602aab077533c185bf7b653af027c1ea 100644 (file)
@@ -88,10 +88,10 @@ class JSONResponseTest extends \Test\TestCase {
                $this->assertEquals($expected, $this->json->render());
        }
 
-       
+
        public function testRenderWithNonUtf8Encoding() {
-               $this->expectException(\Exception::class);
-               $this->expectExceptionMessage('Could not json_encode due to invalid non UTF-8 characters in the array: array (');
+               $this->expectException(\JsonException::class);
+               $this->expectExceptionMessage('Malformed UTF-8 characters, possibly incorrectly encoded');
 
                $params = ['test' => hex2bin('e9')];
                $this->json->setData($params);