mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 11:31:41 +00:00
fix(signal): guard JSON.parse of Signal RPC response with try-catch
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
Peter Steinberger
parent
7d7297f57f
commit
4b78e91acd
@@ -77,7 +77,12 @@ export async function signalRpcRequest<T = unknown>(
|
|||||||
if (!text) {
|
if (!text) {
|
||||||
throw new Error(`Signal RPC empty response (status ${res.status})`);
|
throw new Error(`Signal RPC empty response (status ${res.status})`);
|
||||||
}
|
}
|
||||||
const parsed = JSON.parse(text) as SignalRpcResponse<T>;
|
let parsed: SignalRpcResponse<T>;
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(text) as SignalRpcResponse<T>;
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`Signal RPC returned malformed JSON (status ${res.status})`, { cause: err });
|
||||||
|
}
|
||||||
if (parsed.error) {
|
if (parsed.error) {
|
||||||
const code = parsed.error.code ?? "unknown";
|
const code = parsed.error.code ?? "unknown";
|
||||||
const msg = parsed.error.message ?? "Signal RPC error";
|
const msg = parsed.error.message ?? "Signal RPC error";
|
||||||
|
|||||||
Reference in New Issue
Block a user