(input: URL | RequestInfo, init: any)
| 449 | fetch(url: RequestInfo | URL, init?: RequestInit): Promise<Response> { |
| 450 | // Custom Node.js fetch |
| 451 | const customFetch = async (input: URL | RequestInfo, init: any) => { |
| 452 | try { |
| 453 | const resp = await fetchwithRequestOptions( |
| 454 | new URL(input as any), |
| 455 | { ...init }, |
| 456 | { ...this.requestOptions }, |
| 457 | ); |
| 458 | |
| 459 | // Error mapping to be more helpful |
| 460 | if (!resp.ok) { |
| 461 | if (resp.status === 499) { |
| 462 | return resp; // client side cancellation |
| 463 | } |
| 464 | |
| 465 | const error = await this.parseError(resp); |
| 466 | throw error; |
| 467 | } |
| 468 | |
| 469 | return resp; |
| 470 | } catch (e: any) { |
| 471 | Logger.error(e, { |
| 472 | context: "llm_fetch", |
| 473 | url: String(input), |
| 474 | method: init?.method || "GET", |
| 475 | model: this.model, |
| 476 | provider: this.providerName, |
| 477 | }); |
| 478 | |
| 479 | // Errors to ignore |
| 480 | if (e.message.includes("/api/tags")) { |
| 481 | throw new Error(`Error fetching tags: ${e.message}`); |
| 482 | } else if (e.message.includes("/api/show")) { |
| 483 | throw new Error( |
| 484 | `HTTP ${e.response.status} ${e.response.statusText} from ${e.response.url}\n\n${e.response.body}`, |
| 485 | ); |
| 486 | } else { |
| 487 | if (!isAbortError(e)) { |
| 488 | // Don't pollute console with abort errors. Check on name instead of instanceof, to avoid importing node-fetch here |
| 489 | console.debug( |
| 490 | `${e.message}\n\nCode: ${e.code}\nError number: ${e.errno}\nSyscall: ${e.erroredSysCall}\nType: ${e.type}\n\n${e.stack}`, |
| 491 | ); |
| 492 | } |
| 493 | if ( |
| 494 | e.code === "ECONNREFUSED" && |
| 495 | e.message.includes("http://127.0.0.1:11434") |
| 496 | ) { |
| 497 | const message = (await isOllamaInstalled()) |
| 498 | ? "Unable to connect to local Ollama instance. Ollama may not be running." |
| 499 | : "Unable to connect to local Ollama instance. Ollama may not be installed or may not running."; |
| 500 | throw new Error(message); |
| 501 | } |
| 502 | if ( |
| 503 | e.code === "ECONNREFUSED" && |
| 504 | e.message.includes("http://localhost:8000") |
| 505 | ) { |
| 506 | const isInstalled = await isLemonadeInstalled(); |
| 507 | let message: string; |
| 508 | if (process.platform === "linux") { |
no test coverage detected