{"record":{"id":"02f4e259c785c1a0","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-fetch-pfp","errorCode":null,"errorMessage":"Failed to fetch pfp.","messagePattern":"Failed to fetch pfp\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"frontend/src/models/system.js","lineNumber":496,"sourceCode":"          const logoURL = URL.createObjectURL(blob);\n          return { isCustomLogo, logoURL };\n        }\n        throw new Error(\"Failed to fetch logo!\");\n      })\n      .catch((e) => {\n        console.log(e);\n        return { isCustomLogo: false, logoURL: null };\n      });\n  },\n  fetchPfp: async function (id) {\n    return await fetch(`${API_BASE}/system/pfp/${id}`, {\n      method: \"GET\",\n      cache: \"no-cache\",\n      headers: baseHeaders(),\n    })\n      .then((res) => {\n        if (res.ok && res.status !== 204) return res.blob();\n        throw new Error(\"Failed to fetch pfp.\");\n      })\n      .then((blob) => (blob ? URL.createObjectURL(blob) : null))\n      .catch(() => {\n        return null;\n      });\n  },\n  removePfp: async function () {\n    return await fetch(`${API_BASE}/system/remove-pfp`, {\n      method: \"DELETE\",\n      headers: baseHeaders(),\n    })\n      .then((res) => {\n        if (res.ok) return { success: true, error: null };\n        throw new Error(\"Failed to remove pfp.\");\n      })\n      .catch((e) => {\n        console.log(e);\n        return { success: false, error: e.message };","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/frontend/src/models/system.js#L478-L514","documentation":"Thrown by System.fetchPfp when the GET to /api/system/pfp/{id} returns a non-2xx status OR a 204 (no pfp set). Unlike fetchLogo it DOES send baseHeaders(). The .catch() returns null, so any failure — including the benign 204 — yields null and the UI shows the default avatar.","triggerScenarios":"Calling fetchPfp(userId) when the user has no profile picture (204), when the id does not correspond to a user (404), or when the auth token is rejected (401/403).","commonSituations":"A new user who never uploaded a pfp returns 204 every time; a deleted user's id is passed; the token expired before the avatar render.","solutions":["Treat 204 as 'no avatar' rather than an error condition.","Confirm the id matches an existing user record.","Verify localStorage AUTH_TOKEN is present since baseHeaders() is sent.","Cache the null result to avoid repeated failing requests for the same user."],"exampleFix":"// before\nif (res.ok && res.status !== 204) return res.blob();\nthrow new Error(\"Failed to fetch pfp.\");\n\n// after (204 is benign)\nif (res.status === 204) return null;\nif (!res.ok) throw new Error(`Failed to fetch pfp. (${res.status})`);\nreturn res.blob();","handlingStrategy":"fallback","validationCode":"function validUserId(id) {\n  return (typeof id === \"string\" || typeof id === \"number\") && String(id).length > 0;\n}\n// Also ensure AUTH_TOKEN is set (baseHeaders is sent).","typeGuard":"/** @param {any} r @returns {r is string|null} */\nfunction isObjectUrlOrNull(r) { return r === null || typeof r === \"string\"; }","tryCatchPattern":"const url = await System.fetchPfp(id);\nif (!isObjectUrlOrNull(url) || !url) { renderDefaultAvatar(); }","preventionTips":["Treat 204 as 'no avatar' — benign, not an error.","Cache null results per user id to avoid repeat failing calls.","Revoke object URLs on unmount."],"tags":["network","profile","avatar","auth"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}