{"record":{"id":"94844346ef609e77","repo":"upstash/context7","slug":"context7urlerror","errorCode":null,"errorMessage":"Context7UrlError","messagePattern":"Context7UrlError","errorType":"exception","errorClass":"Context7UrlError","httpStatus":null,"severity":"error","filePath":"packages/sdk/src/http/index.ts","lineNumber":59,"sourceCode":"    keepAlive: boolean;\n  };\n  public readonly retry: RetryPolicy;\n\n  private readonly fetch: Context7Fetch;\n  private readonly authToken?: string | AuthTokenProvider;\n  private readonly onResponse?: (metadata: Context7ResponseMetadata) => void;\n\n  public constructor(config: HttpClientConfig) {\n    this.options = {\n      cache: config.cache,\n      signal: config.signal,\n      timeout: config.timeout ?? DEFAULT_TIMEOUT,\n      keepAlive: config.keepAlive ?? true,\n    };\n    validateTimeout(this.options.timeout);\n\n    this.baseUrl = config.baseUrl.replace(/\\/$/, \"\");\n    if (!isHttpUrl(this.baseUrl)) throw new Context7UrlError(this.baseUrl);\n\n    this.headers = { \"Content-Type\": \"application/json\", ...config.headers };\n    this.authToken = config.authToken;\n    if (!config.fetch && !globalThis.fetch) {\n      throw new TypeError(\"A fetch implementation is required\");\n    }\n    this.fetch = config.fetch ?? globalThis.fetch.bind(globalThis);\n    this.onResponse = config.onResponse;\n    this.retry = createRetryPolicy(config.retry);\n  }\n\n  public async request<TResult>(request: Context7Request): Promise<Context7Response<TResult>> {\n    const method = request.method ?? \"POST\";\n    const abortState = createAbortState(\n      [resolveSignal(this.options.signal), request.signal],\n      request.timeout ?? this.options.timeout\n    );\n    try {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/upstash/context7/blob/4416fb855b8f752be735e34f943b5d0762701aad/packages/sdk/src/http/index.ts#L41-L77","documentation":"Context7UrlError is thrown by the HTTP client constructor when the configured baseUrl, after trimming a trailing slash, is not a valid HTTP(S) URL (per isHttpUrl). It signals a malformed or wrongly-schemed base URL at client initialization time.","triggerScenarios":"Constructing the client with baseUrl values like 'localhost:3000' (no scheme), 'ftp://x', 'context7.com' without protocol, an empty string after stripping, or strings containing spaces/invalid characters.","commonSituations":"Omitting the 'https://' scheme in config files; building the URL by string concatenation that drops the scheme; using a placeholder value left in .env; passing a path like '/api' instead of a full origin.","solutions":["Set baseUrl to a full URL with scheme, e.g. 'https://context7.com'","Add 'https://' if you only supplied a hostname","Trim whitespace and remove stray characters from the configured value","Validate the URL with new URL(value) and checking ^https?: before constructing the client"],"exampleFix":"// before\nconst client = new Context7Client({ baseUrl: 'context7.com' });\n// after\nconst client = new Context7Client({ baseUrl: 'https://context7.com' });","handlingStrategy":"validation","validationCode":"function isValidBaseUrl(v) {\n  try { const u = new URL(v); return u.protocol === 'http:' || u.protocol === 'https:'; } catch { return false; }\n}","typeGuard":"function isHttpUrl(v: unknown): v is string {\n  if (typeof v !== 'string') return false;\n  try { const u = new URL(v); return u.protocol === 'http:' || u.protocol === 'https:'; } catch { return false; }\n}","tryCatchPattern":"try {\n  const client = new Context7Client({ baseUrl });\n} catch (e) {\n  if (e instanceof Context7UrlError) {\n    console.error(`baseUrl \"${e.url ?? baseUrl}\" is not a valid http(s) URL`);\n  } else { throw e; }\n}","preventionTips":["Always include the scheme (https://) in configured base URLs","Validate the URL with new URL() at config-load time, before constructing clients","Keep base URLs in one config module so they are validated in a single place","Strip whitespace and trailing slashes from config values early"],"tags":["url","config","validation","http"],"backgroundTag":"invalid-url-format","analyzedSha":"4416fb855b8f752be735e34f943b5d0762701aad","analyzedAt":"2026-09-16T20:28:07.148Z","contentChangedAt":"2026-09-16T20:28:07.148Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}