janhq/jan · warning

error.message

Error message

error.message

What it means

Not a distinct error type: this is the re-throw path that preserves structured errors ('Authentication failed', 'Access forbidden', 'Models endpoint not found', 'Failed to fetch models from') thrown earlier in fetchModelsFromProvider. It re-wraps the message in a new Error so the original, specific message reaches the caller unchanged.

Solutions

  1. Diagnose based on the preserved message (see the 401/403/404/status-specific errors).
  2. If you control the code, prefer re-throwing the original error instead of allocating a new Error to keep the original stack.
  3. Check console.error output ('Error fetching models from provider') for the original stack.

Example fix

// before
throw new Error(error.message)
// after (preserves stack and type)
throw error
Defensive patterns

Strategy: type-guard

Type guard

function isStructuredFetchError(e: unknown): e is Error {
  const prefixes = ['Authentication failed', 'Access forbidden', 'Models endpoint not found', 'Failed to fetch models from']
  return e instanceof Error && prefixes.some(p => e.message.startsWith(p))
}

Try / catch

try {
  await fetchModelsFromProvider(provider)
} catch (e) {
  if (isStructuredFetchError(e)) handleProviderHttpError(e)
  else handleUnexpectedError(e)
}

Prevention

When it happens

Trigger: Any of the four structured errors above is thrown inside the try block and then caught by the outer catch; because the message starts with a known prefix, it is re-thrown as-is.

Common situations: Developers see this in stack traces when debugging provider fetch failures; the visible message is the underlying 401/403/404/generic HTTP error, not a new failure.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of janhq/jan@7205d770c1 (2026-09-17). Data as JSON: /api/errors/f7b87bd2166d879a. Report an issue: GitHub.

Appendix: source

Thrown at web-app/src/services/providers/tauri.ts:267

      )
    } catch (error) {
      console.error('Error fetching models from provider:', error)

      // Preserve structured error messages thrown above
      const structuredErrorPrefixes = [
        'Authentication failed',
        'Access forbidden',
        'Models endpoint not found',
        'Failed to fetch models from',
      ]

      if (
        error instanceof Error &&
        structuredErrorPrefixes.some((prefix) =>
          (error as Error).message.startsWith(prefix)
        )
      ) {
        throw new Error(error.message)
      }

      // Provide helpful error message for any connection errors
      if (error instanceof Error && error.message.includes('fetch')) {
        throw new Error(
          `Cannot connect to ${provider.provider} at ${provider.base_url}. Please check that the service is running and accessible.`
        )
      }

      // Generic fallback
      throw new Error(
        `Unexpected error while fetching models from ${provider.provider}: ${error instanceof Error ? error.message : 'Unknown error'}`
      )
    }
  }

  async updateSettings(
    providerName: string,

View on GitHub (pinned to 7205d770c1)