This commit is contained in:
2026-06-24 21:15:14 +08:00
parent 7455dc8d58
commit 3daa4021ec
3 changed files with 6 additions and 3 deletions
+2 -1
View File
@@ -97,7 +97,8 @@ class ConstrictResponse extends Message implements ResponseInterface
*/
public function json(array $content, int $statusCode = 200): static
{
$this->stream->write(json_encode($content, JSON_UNESCAPED_UNICODE));
$encoded = json_encode($content, JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE);
$this->stream->write($encoded === false ? '{"error":"json encode failed"}' : $encoded);
return $this->withContentType(ContentType::JSON)->withStatus($statusCode);
}