mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 01:11:23 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -32,7 +32,9 @@ export function getHeadersWithAuth(url: string, headers: Record<string, string>
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
const hasAuthHeader = Object.keys(headers).some((key) => key.toLowerCase() === "authorization");
|
||||
if (hasAuthHeader) return headers;
|
||||
if (hasAuthHeader) {
|
||||
return headers;
|
||||
}
|
||||
if (parsed.username || parsed.password) {
|
||||
const auth = Buffer.from(`${parsed.username}:${parsed.password}`).toString("base64");
|
||||
return { ...headers, Authorization: `Basic ${auth}` };
|
||||
@@ -65,7 +67,9 @@ function createCdpSender(ws: WebSocket) {
|
||||
};
|
||||
|
||||
const closeWithError = (err: Error) => {
|
||||
for (const [, p] of pending) p.reject(err);
|
||||
for (const [, p] of pending) {
|
||||
p.reject(err);
|
||||
}
|
||||
pending.clear();
|
||||
try {
|
||||
ws.close();
|
||||
@@ -77,9 +81,13 @@ function createCdpSender(ws: WebSocket) {
|
||||
ws.on("message", (data) => {
|
||||
try {
|
||||
const parsed = JSON.parse(rawDataToString(data)) as CdpResponse;
|
||||
if (typeof parsed.id !== "number") return;
|
||||
if (typeof parsed.id !== "number") {
|
||||
return;
|
||||
}
|
||||
const p = pending.get(parsed.id);
|
||||
if (!p) return;
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
pending.delete(parsed.id);
|
||||
if (parsed.error?.message) {
|
||||
p.reject(new Error(parsed.error.message));
|
||||
@@ -104,7 +112,9 @@ export async function fetchJson<T>(url: string, timeoutMs = 1500, init?: Request
|
||||
try {
|
||||
const headers = getHeadersWithAuth(url, (init?.headers as Record<string, string>) || {});
|
||||
const res = await fetch(url, { ...init, headers, signal: ctrl.signal });
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP ${res.status}`);
|
||||
}
|
||||
return (await res.json()) as T;
|
||||
} finally {
|
||||
clearTimeout(t);
|
||||
@@ -117,7 +127,9 @@ export async function fetchOk(url: string, timeoutMs = 1500, init?: RequestInit)
|
||||
try {
|
||||
const headers = getHeadersWithAuth(url, (init?.headers as Record<string, string>) || {});
|
||||
const res = await fetch(url, { ...init, headers, signal: ctrl.signal });
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP ${res.status}`);
|
||||
}
|
||||
} finally {
|
||||
clearTimeout(t);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user