Skip to content

Commit 21fcd6e

Browse files
Sunrisepeakclaude
andcommitted
fix: use error_handler_t::replace for UTF-8 in JSON dump
Prevents json::type_error.316 when payload strings contain invalid UTF-8 bytes. Replaces bad bytes with U+FFFD instead of throwing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2c13c06 commit 21fcd6e

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/providers/anthropic.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ private:
456456
tinyhttps::HttpRequest req;
457457
req.method = tinyhttps::Method::POST;
458458
req.url = config_.baseUrl + std::string(endpoint);
459-
req.body = payload.dump();
459+
req.body = payload.dump(-1, ' ', false, Json::error_handler_t::replace);
460460

461461
req.headers["Content-Type"] = "application/json";
462462
req.headers["x-api-key"] = config_.apiKey;

src/providers/openai.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ private:
453453
tinyhttps::HttpRequest req;
454454
req.method = tinyhttps::Method::POST;
455455
req.url = config_.baseUrl + std::string(endpoint);
456-
req.body = payload.dump();
456+
req.body = payload.dump(-1, ' ', false, Json::error_handler_t::replace);
457457

458458
req.headers["Content-Type"] = "application/json";
459459
req.headers["Authorization"] = "Bearer " + config_.apiKey;

0 commit comments

Comments
 (0)