refactor(open-sse): extract safeParseJSON util, dedup tryParseJSON (B5)
Consolidate two tryParseJSON variants into helpers/jsonUtil.js with explicit fallback param. Preserve exact per-call semantics: openai-to-claude passthrough (fallback=str), geminiHelper null. geminiHelper keeps tryParseJSON re-export. No behavior change; gate: no regression. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
87fe069e9e
commit
b87cf0c96a
4 files changed
+12
-19
No files matched your search
@@ -0,0 +1,5 @@
|
||||
// Safe JSON.parse: non-string passthrough; on parse error return caller-chosen `fallback`.
|
||||
export function safeParseJSON(str, fallback) {
|
||||
if (typeof str !== "string") return str;
|
||||
try { return JSON.parse(str); } catch { return fallback; }
|
||||
}
|
||||
Reference in new issue
Block a user