jackwener/OpenCLI · error · CliError
REQUEST_FAILED
REQUEST_FAILED
Error message
Failed to request Gitee search API: ${response.status} What it means
CliError with code REQUEST_FAILED thrown when the HTTP response from the Gitee search API (so.gitee.com) has a non-ok status. The library surfaces the status code and advises retrying later or verifying network access to so.gitee.com. It indicates the upstream request failed before any result parsing.
Source
Thrown at clis/gitee/search.js:100
const limit = clampLimit(args.limit);
const encodedKeyword = encodeURIComponent(keyword);
const searchUrl = `${GITEE_SEARCH_URL}?q=${encodedKeyword}&type=repository`;
const fetchSize = Math.max(10, limit);
const apiUrl = new URL(GITEE_SEARCH_API);
apiUrl.searchParams.set('q', keyword);
apiUrl.searchParams.set('from', '0');
apiUrl.searchParams.set('size', String(fetchSize));
await page.goto(searchUrl);
await page.wait(2);
const response = await fetch(apiUrl.toString(), {
headers: {
Accept: 'application/json',
'User-Agent': 'Mozilla/5.0',
Referer: searchUrl,
},
});
if (!response.ok) {
throw new CliError('REQUEST_FAILED', `Failed to request Gitee search API: ${response.status}`, 'Try again later or verify network access to so.gitee.com');
}
const payload = await response.json();
const payloadRecord = asRecord(payload);
const hitsRecord = asRecord(payloadRecord?.hits);
const rawRows = Array.isArray(hitsRecord?.hits) ? hitsRecord.hits : [];
if (rawRows.length === 0) {
throw new CliError('NOT_FOUND', 'No Gitee repository search results found', 'Try a different keyword or check whether Gitee search API changed');
}
const seen = new Set();
const rows = [];
for (let i = 0; i < rawRows.length && rows.length < limit; i++) {
const row = asRecord(rawRows[i]);
const fields = asRecord(row?.fields);
if (!fields)
continue;
const name = normalizeText(getFirstText(fields.title));
const repoUrl = normalizeUrl(getFirstText(fields.url));
if (!name || !repoUrl)View on GitHub (pinned to 49907e53dc)
Solutions
- Retry after a delay; the hint suggests 'Try again later' for transient 5xx/429
- Check network access to so.gitee.com (curl -I https://so.gitee.com) and proxy/VPN settings
- Reduce request frequency to avoid Gitee rate limiting/bot detection
- Log response.status and inspect the body to see if Gitee changed or blocked the API
- Fall back to scraping the search HTML page or use Gitee's official REST API with a token
Defensive patterns
Strategy: retry
Validate before calling
// Pre-flight connectivity check
const res = await fetch('https://so.gitee.com', { method: 'HEAD' }).catch(() => null);
if (!res) { console.error('so.gitee.com unreachable — check network/proxy'); process.exit(1); } Type guard
function isRequestFailed(e) {
return e instanceof Error && e.code === 'REQUEST_FAILED';
} Try / catch
try {
rows = await giteeSearch(keyword);
} catch (e) {
if (e.code === 'REQUEST_FAILED') {
// exponential backoff retry for transient 429/5xx
await sleep(2000);
rows = await giteeSearch(keyword);
} else throw e;
} Prevention
- Add exponential backoff with jitter on 429/5xx responses
- Throttle request rate to stay under Gitee rate limits
- Keep browser-context headers (UA, Referer) intact when calling the endpoint
- Monitor so.gitee.com availability and alert on sustained failures
When it happens
Trigger: fetch(GITEE_SEARCH_API) returns response.ok === false — e.g. HTTP 403/429 (rate limit / bot detection), 5xx server errors, or a proxy error while requesting the search endpoint with the browser-context headers (Accept json, Mozilla UA, Referer: searchUrl).
Common situations: Gitee rate-limiting or WAF blocking automated requests; so.gitee.com temporarily down or returning 5xx; corporate proxy/firewall blocking so.gitee.com; stale session cookies triggering 403; API endpoint changed and now rejects the request.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- autohome ${contextHint} HTTP ${resp.status}
- Ctrip flight API returned HTTP ${status || 'unknown'}
- dongchedi ${contextHint} HTTP ${resp.status}
- eastmoney convertible failed: HTTP ${resp.status}
- HTTP_ERROR
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/252f2b1ddc6e2935.
Report an issue: GitHub.