{"record":{"id":"8aa90952ef9bad8e","repo":"Mintplex-Labs/anything-llm","slug":"response-error-failed-to-update-settings","errorCode":null,"errorMessage":"${response.error || \"Failed to update settings\"}","messagePattern":"\\$\\{response\\.error \\|\\| \"Failed to update settings\"\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/models/communityHub.js","lineNumber":86,"sourceCode":"        };\n      });\n  },\n\n  /**\n   * Update the hub settings (API key, etc.)\n   * @param {Object} data - The data to update.\n   * @returns {Promise<{success: boolean, error: string | null}>}\n   */\n  updateSettings: async (data) => {\n    return await fetch(`${API_BASE}/community-hub/settings`, {\n      method: \"POST\",\n      headers: baseHeaders(),\n      body: JSON.stringify(data),\n    })\n      .then(async (res) => {\n        const response = await res.json();\n        if (!res.ok)\n          throw new Error(response.error || \"Failed to update settings\");\n        return { success: true, error: null };\n      })\n      .catch((e) => ({\n        success: false,\n        error: e.message,\n      }));\n  },\n\n  /**\n   * Get the hub settings (API key, etc.)\n   * @returns {Promise<{connectionKey: string | null, error: string | null}>}\n   */\n  getSettings: async () => {\n    return await fetch(`${API_BASE}/community-hub/settings`, {\n      method: \"GET\",\n      headers: baseHeaders(),\n    })\n      .then(async (res) => {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/frontend/src/models/communityHub.js#L68-L104","documentation":"Thrown from `updateSettings` on a non-ok `POST /api/community-hub/settings`. Reads `response.error` from the parsed JSON body (correct pattern), falling back to 'Failed to update settings'. Typically a 400/422 when the submitted connection key is malformed, or 401 for non-admin sessions.","triggerScenarios":"Submitting an empty or invalid connection key; key fails server-side format validation (422); 401 expired/ non-admin session; 500 backend persistence failure.","commonSituations":"User pastes a key with stray whitespace or wrong format; session expires before saving; backend settings store write error.","solutions":["Trim/validate the connection key client-side before posting.","Read `error` from the returned `{ success, error }` for the precise reason.","On 401 re-authenticate; on 422 fix per the server message.","Confirm the key matches the hub's expected format/length."],"exampleFix":"// before\nawait CommunityHub.updateSettings({ connectionKey: rawKey });\n\n// after\nconst key = String(rawKey).trim();\nif (!key) throw new Error('Connection key is required');\nconst { success, error } = await CommunityHub.updateSettings({ connectionKey: key });\nif (!success) throw new Error(error || 'Failed to update settings');","handlingStrategy":"validation","validationCode":"function validateSettingsPayload(data) {\n  if (!data || typeof data !== 'object') throw new Error('Settings payload is required');\n  if ('connectionKey' in data && typeof data.connectionKey !== 'string') {\n    throw new Error('connectionKey must be a string');\n  }\n  if ('connectionKey' in data && !data.connectionKey.trim()) {\n    throw new Error('connectionKey cannot be empty');\n  }\n}","typeGuard":"function isSettingsPayload(v) {\n  return !!v && typeof v === 'object' && (!('connectionKey' in v) || typeof v.connectionKey === 'string');\n}","tryCatchPattern":"const { success, error } = await CommunityHub.updateSettings(data);\nif (!success) showToast(error || 'Failed to update settings');","preventionTips":["Trim and validate the connection key client-side before posting.","Read the returned `error` for the precise server reason.","Re-authenticate on 401."],"tags":["frontend","community-hub","settings","validation","fetch"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}