jackwener/OpenCLI · error · CommandExecutionError

weread-official ${apiName} HTTP ${response.status}

Error message

weread-official ${apiName} HTTP ${response.status}

What it means

The gateway responded with a non-2xx HTTP status. callGateway raises CommandExecutionError naming the api and status, with the hint that either the gateway is down or WEREAD_API_KEY is no longer valid.

Source

Thrown at clis/weread-official/utils.js:105

                'Content-Type': 'application/json',
            },
            body: JSON.stringify(body),
            signal: controller.signal,
        });
    }
    catch (error) {
        if (error?.name === 'AbortError') {
            throw new TimeoutError(`weread-official ${apiName}`, Math.round(timeoutMs / 1000));
        }
        const detail = error instanceof Error ? error.message : String(error);
        throw new CommandExecutionError(`weread-official ${apiName} request failed`, detail);
    }
    finally {
        clearTimeout(timer);
    }

    if (!response.ok) {
        throw new CommandExecutionError(
            `weread-official ${apiName} HTTP ${response.status}`,
            'Check WeRead gateway availability and that WEREAD_API_KEY is still valid.',
        );
    }

    let payload;
    try {
        payload = await response.json();
    }
    catch (error) {
        const detail = error instanceof Error ? error.message : String(error);
        throw new CommandExecutionError(`weread-official ${apiName} returned invalid JSON`, detail);
    }

    if (payload && typeof payload === 'object' && payload.upgrade_info) {
        const info = payload.upgrade_info;
        const required = info?.required_version ?? info?.version ?? 'unknown';
        const message = info?.message ?? 'WeRead skill version is outdated';

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Confirm WEREAD_API_KEY is set and current; regenerate and re-export if rejected.
  2. Re-run the command to check for transient 5xx.
  3. Check gateway status / maintenance announcements.
  4. Back off on 429 and retry later; throttle request rate.

Example fix

// before
export WEREAD_API_KEY=old_key
// after (regenerate at the WeRead console, then)
export WEREAD_API_KEY=<freshly_generated_key>
Defensive patterns

Strategy: retry

Validate before calling

if (!process.env.WEREAD_API_KEY) throw new Error('WEREAD_API_KEY is not set — export it before calling the gateway');

Type guard

const isHttpError = (e) => e instanceof CommandExecutionError && /HTTP \d{3}/.test(e.message);

Try / catch

try {
  return await callGateway(apiName, params);
} catch (e) {
  const m = e instanceof CommandExecutionError && /HTTP (\d{3})/.exec(e.message);
  if (m && ['502','503','504'].includes(m[1])) {
    await sleep(2000); return callGateway(apiName, params); // transient
  }
  if (m && m[1] === '429') { await sleep(60000); return callGateway(apiName, params); }
  throw e;
}

Prevention

When it happens

Trigger: HTTP 401/403 from an expired or revoked WEREAD_API_KEY; HTTP 502/503 from gateway maintenance or outage; HTTP 404 after the gateway path changed; HTTP 429 rate limiting.

Common situations: Key rotated upstream while a cached key remains in the environment; gateway deployed behind a new path; burst scripts tripping rate limits.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/d7cd61c8c2418f30. Report an issue: GitHub.