{"record":{"id":"2857ddbc251c24f5","repo":"TryGhost/Ghost","slug":"failed-to-edit-comment","errorCode":null,"errorMessage":"Failed to edit comment","messagePattern":"Failed to edit comment","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/comments-ui/src/utils/api.ts","lineNumber":252,"sourceCode":"                });\n            },\n            edit({comment}: {comment: Partial<Comment> & {id: string}}) {\n                const body = {\n                    comments: [comment]\n                };\n                const url = endpointFor({type: 'members', resource: `comments/${comment.id}`});\n                return makeRequest({\n                    url,\n                    method: 'PUT',\n                    headers: {\n                        'Content-Type': 'application/json'\n                    },\n                    body: JSON.stringify(body)\n                }).then(function (res) {\n                    if (res.ok) {\n                        return res.json();\n                    } else {\n                        throw new Error('Failed to edit comment');\n                    }\n                });\n            },\n            read(commentId: string) {\n                const url = endpointFor({type: 'members', resource: `comments/${commentId}`});\n                return makeRequest({\n                    url,\n                    method: 'GET',\n                    credentials: 'same-origin'\n                }).then(function (res) {\n                    if (res.ok) {\n                        return res.json();\n                    } else {\n                        throw new Error('Failed to read comment');\n                    }\n                });\n            },\n            like({comment}: {comment: {id: string}}) {","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/TryGhost/Ghost/blob/47d8b0e2ad2fd4757d3bc45f46c3ac165ff8a1fe/apps/comments-ui/src/utils/api.ts#L234-L270","documentation":"comments.edit() PUTs an updated comment to /members/api/comments/{comment.id} with a body of {comments: [comment]}. If the response is not ok, it throws. Editing is typically restricted to the comment author within an edit window, so 403 is a common failure.","triggerScenarios":"The PUT returns 4xx/5xx. The member is not the author (403), the edit window has expired (403), the comment was deleted between render and edit (404), the member session expired (401), or the edited content fails validation (422).","commonSituations":"A member tries to edit a comment after the configured edit time window elapsed. A member edits a comment they did not author (UI should prevent this but a race or spoofed id can trigger it). The comment was removed by a moderator but still appears in the client cache.","solutions":["Check the Network tab PUT response status and body.","If 403, inform the user the edit window has passed or they lack permission; disable the edit affordance.","If 404, remove the comment from local state since it no longer exists.","Refresh the comment from the server before allowing an edit to catch deletions."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"function canEditComment(comment: {id: string}, memberId: string | null, editWindowMs: number, createdAt: string): boolean {\n  return Boolean(memberId) && Boolean(comment.id)\n    && Date.now() - new Date(createdAt).getTime() < editWindowMs;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const result = await api.comments.edit({comment});\n} catch (e) {\n  if (e instanceof Error && e.message === 'Failed to edit comment') {\n    // likely 403 edit window expired or 404 deleted\n  }\n}","preventionTips":["Only show the edit affordance within the configured edit time window.","Refresh the comment from the server before editing to catch deletions.","Disable the edit button during the PUT to prevent duplicate requests."],"tags":["network","fetch","comments-ui","comments","edit","write"],"backgroundTag":null,"analyzedSha":"47d8b0e2ad2fd4757d3bc45f46c3ac165ff8a1fe","analyzedAt":"2026-08-13T01:25:26.651Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}