@pylonsync/react 0.3.379 → 0.3.380
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/index.ts +24 -0
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.3.
|
|
6
|
+
"version": "0.3.380",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.ts",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"prepack": "bun run build"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@pylonsync/sdk": "0.3.
|
|
18
|
-
"@pylonsync/sync": "0.3.
|
|
17
|
+
"@pylonsync/sdk": "0.3.380",
|
|
18
|
+
"@pylonsync/sync": "0.3.380"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": ">=19.0.0"
|
package/src/index.ts
CHANGED
|
@@ -525,6 +525,30 @@ export async function* streamFn(
|
|
|
525
525
|
accept: "text/event-stream",
|
|
526
526
|
},
|
|
527
527
|
);
|
|
528
|
+
// The server only upgrades to SSE once the handler actually calls
|
|
529
|
+
// ctx.stream. A function that completes without streaming answers
|
|
530
|
+
// with plain JSON (Content-Type: application/json) — the raw return
|
|
531
|
+
// value on 200, `{"error":{code,message}}` on 400 — so SSE-capable
|
|
532
|
+
// clients that hit a non-streaming function still get a result.
|
|
533
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
534
|
+
if (!contentType.includes("text/event-stream")) {
|
|
535
|
+
const text = await res.text();
|
|
536
|
+
if (!res.ok) {
|
|
537
|
+
let message = `Stream failed: HTTP ${res.status}`;
|
|
538
|
+
try {
|
|
539
|
+
const err = JSON.parse(text) as { error?: { message?: string } };
|
|
540
|
+
if (err.error?.message) message = err.error.message;
|
|
541
|
+
} catch {
|
|
542
|
+
// non-JSON error body — keep the HTTP status message
|
|
543
|
+
}
|
|
544
|
+
throw new Error(message);
|
|
545
|
+
}
|
|
546
|
+
try {
|
|
547
|
+
return JSON.parse(text) as unknown;
|
|
548
|
+
} catch {
|
|
549
|
+
return text;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
528
552
|
if (!res.ok || !res.body) {
|
|
529
553
|
throw new Error(`Stream failed: HTTP ${res.status}`);
|
|
530
554
|
}
|