Skip to content

Commit

Permalink
NEXT-19835 - Fix 'Malformed UTF-8 characters, possibly incorrectly en…
Browse files Browse the repository at this point in the history
…coded' Error On Sync Api

fixes #2289
  • Loading branch information
alessandroaussems authored and SimonVorgers committed Jan 31, 2022
1 parent 82dc4b1 commit 5e62942
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
@@ -0,0 +1,8 @@
---
title: Fix 'Malformed UTF-8 characters, possibly incorrectly encoded' Error
issue:
author: Alessandro Aussems
author_email: me@alessandroaussems.be
---
# Core
* Add `createResponse` in `src/Core/Framework/Api/Controller/SyncController.php` that adds the **JSON_INVALID_UTF8_SUBSTITUTE** encoding option to the response
15 changes: 12 additions & 3 deletions src/Core/Framework/Api/Controller/SyncController.php
Expand Up @@ -159,13 +159,22 @@ public function sync(Request $request, Context $context): JsonResponse
});

if (Feature::isActive('FEATURE_NEXT_15815')) {
return new JsonResponse($result, Response::HTTP_OK);
return $this->createResponse($result, Response::HTTP_OK);
}

if ($behavior->failOnError() && !$result->isSuccess()) {
return new JsonResponse($result, Response::HTTP_BAD_REQUEST);
return $this->createResponse($result, Response::HTTP_BAD_REQUEST);
}

return new JsonResponse($result, Response::HTTP_OK);
return $this->createResponse($result, Response::HTTP_OK);
}

private function createResponse(SyncResult $result, int $statusCode = 200): JsonResponse
{
$response = new JsonResponse(null, $statusCode);
$response->setEncodingOptions(\JSON_INVALID_UTF8_SUBSTITUTE);
$response->setData($result);

return $response;
}
}

0 comments on commit 5e62942

Please sign in to comment.