alibaba/page-agent · error · InvokeError

NETWORK_ERROR

NETWORK_ERROR

Error message

Network request failed

What it means

The underlying fetch call to the OpenAI-compatible endpoint failed before receiving an HTTP response — DNS failure, connection refused, TLS error, network offline, or a non-abort fetch exception. The library re-throws AbortError untouched and wraps everything else in a NETWORK_ERROR InvokeError with the original error as cause. The raw error is also console.error'd before throwing.

Source

Thrown at packages/llms/src/OpenAIClient.ts:88

		}
		const finalRequestBody = transformedBody ?? requestBody

		// 2. Call API
		let response: Response
		try {
			response = await this.fetch(`${this.config.baseURL}/chat/completions`, {
				method: 'POST',
				headers: {
					'Content-Type': 'application/json',
					...(this.config.apiKey && { Authorization: `Bearer ${this.config.apiKey}` }),
				},
				body: JSON.stringify(finalRequestBody),
				signal: abortSignal,
			})
		} catch (error: unknown) {
			if ((error as any)?.name === 'AbortError') throw error
			console.error(error)
			throw new InvokeError(InvokeErrorTypes.NETWORK_ERROR, 'Network request failed', error)
		}

		// 3. Handle HTTP errors
		if (!response.ok) {
			let errorData: any
			try {
				errorData = await response.json()
			} catch (error) {
				if ((error as any)?.name === 'AbortError') throw error
			}
			const errorMessage = errorData?.error?.message || response.statusText

			if (response.status === 401 || response.status === 403) {
				throw new InvokeError(
					InvokeErrorTypes.AUTH_ERROR,
					`Authentication failed: ${errorMessage}`,
					errorData
				)

View on GitHub (pinned to d02db1ee7c)

Solutions

  1. Verify the endpoint is reachable: curl -v <baseURL>/chat/completions from the same machine/network
  2. Check baseURL spelling — scheme, host, port, and path prefix (e.g. /v1)
  3. If behind a proxy or using a local server, confirm it's running and listening on the expected interface
  4. In a browser/extension context, check CORS headers or host_permissions for the baseURL origin
  5. Inspect the preserved cause (InvokeError cause) and the console.error output for the precise fetch failure reason
Defensive patterns

Strategy: retry

Validate before calling

// verify reachability before first use (Node)
await fetch(new URL('/models', cfg.baseURL), { method: 'HEAD' })
  .then(r => console.log('endpoint reachable:', r.status))
  .catch(err => { throw new Error(`Unreachable baseURL ${cfg.baseURL}: ${err.message}`) })

Type guard

const isNetworkError = (e: unknown): e is InvokeError =>
  e instanceof InvokeError && e.code === 'NETWORK_ERROR'

Try / catch

try {
  await client.invoke(req)
} catch (e) {
  if (isNetworkError(e)) {
    await backoff(Math.random() * 1000) // transient DNS/socket issues often clear
    return client.invoke(req)
  }
  throw e
}

Prevention

When it happens

Trigger: fetch() to config.baseURL rejects: unreachable host (wrong baseURL like localhost port not running), DNS resolution failure, self-signed cert rejected, firewall/proxy blocking the request, browser CORS failure, or the page going offline. Any caller of invoke() can hit this.

Common situations: Typo in baseURL (missing scheme, wrong port); corporate proxy intercepting HTTPS; running a local LLM server (ollama/llama.cpp) that isn't started; extension making cross-origin requests without host permissions; offline dev environment.

Related errors


AI-assisted analysis of alibaba/page-agent@d02db1ee7c (2026-08-28). Data as JSON: /api/errors/4411d41965de0870. Report an issue: GitHub.