Mintplex-Labs/anything-llm · error

${response.error || "Failed to fetch settings"}

Error message

${response.error || "Failed to fetch settings"}

What it means

Thrown from `getSettings` on a non-ok `GET /api/community-hub/settings`. Reads `response.error` from JSON, falling back to 'Failed to fetch settings'. Returns `{ connectionKey, error }`. Mostly a read failure: auth, backend, or persistence.

Source

Thrown at frontend/src/models/communityHub.js:107

      .catch((e) => ({
        success: false,
        error: e.message,
      }));
  },

  /**
   * Get the hub settings (API key, etc.)
   * @returns {Promise<{connectionKey: string | null, error: string | null}>}
   */
  getSettings: async () => {
    return await fetch(`${API_BASE}/community-hub/settings`, {
      method: "GET",
      headers: baseHeaders(),
    })
      .then(async (res) => {
        const response = await res.json();
        if (!res.ok)
          throw new Error(response.error || "Failed to fetch settings");
        return { connectionKey: response.connectionKey, error: null };
      })
      .catch((e) => ({
        connectionKey: null,
        error: e.message,
      }));
  },

  /**
   * Fetch the explore items from the community hub that are publicly available.
   * @returns {Promise<{agentSkills: {items: [], hasMore: boolean, totalCount: number}, systemPrompts: {items: [], hasMore: boolean, totalCount: number}, slashCommands: {items: [], hasMore: boolean, totalCount: number}}>}
   */
  fetchExploreItems: async () => {
    return await fetch(`${API_BASE}/community-hub/explore`, {
      method: "GET",
      headers: baseHeaders(),
    })
      .then((res) => res.json())

View on GitHub (pinned to 526360e320)

Solutions

  1. On 401, redirect to login and re-fetch after auth.
  2. Read `error` from the returned object for the backend's reason.
  3. Ensure the response is JSON (not an HTML login redirect) — guard the `res.json()` call.
  4. Check backend logs for the 500 root cause.

Example fix

// before
const { connectionKey, error } = await CommunityHub.getSettings();

// after — guard parse + handle auth
const { connectionKey, error } = await CommunityHub.getSettings();
if (error && /401|unauthor/i.test(error)) {
  await redirectToLogin();
  return;
}
if (error) throw new Error(error);
Defensive patterns

Strategy: try-catch

Validate before calling

// Mostly a read; pre-check auth state:
function assertAuthed() {
  if (!getToken()) throw new Error('Not authenticated');
}

Type guard

function isAuthOrParseError(msg) { return /401|unauthor|Unexpected token|JSON/i.test(String(msg || '')); }

Try / catch

const { connectionKey, error } = await CommunityHub.getSettings();
if (error) {
  if (/401|unauthor/i.test(error)) { await redirectToLogin(); return; }
  showToast(error);
}

Prevention

When it happens

Trigger: 401/403 (non-admin or expired session), 500 backend settings store error, network failure (covered by catch), malformed response body causing `.json()` to throw.

Common situations: Loading the community-hub settings page after session expiry; backend migration that changed the settings shape; reverse proxy returning HTML (login page) so JSON parse fails.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/1b64b5788d492dd9. Report an issue: GitHub.