TryGhost/Ghost · error · Error

Failed to edit comment

Error message

Failed to edit comment

What it means

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.

Source

Thrown at apps/comments-ui/src/utils/api.ts:252

                });
            },
            edit({comment}: {comment: Partial<Comment> & {id: string}}) {
                const body = {
                    comments: [comment]
                };
                const url = endpointFor({type: 'members', resource: `comments/${comment.id}`});
                return makeRequest({
                    url,
                    method: 'PUT',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(body)
                }).then(function (res) {
                    if (res.ok) {
                        return res.json();
                    } else {
                        throw new Error('Failed to edit comment');
                    }
                });
            },
            read(commentId: string) {
                const url = endpointFor({type: 'members', resource: `comments/${commentId}`});
                return makeRequest({
                    url,
                    method: 'GET',
                    credentials: 'same-origin'
                }).then(function (res) {
                    if (res.ok) {
                        return res.json();
                    } else {
                        throw new Error('Failed to read comment');
                    }
                });
            },
            like({comment}: {comment: {id: string}}) {

View on GitHub (pinned to 47d8b0e2ad)

Solutions

  1. Check the Network tab PUT response status and body.
  2. If 403, inform the user the edit window has passed or they lack permission; disable the edit affordance.
  3. If 404, remove the comment from local state since it no longer exists.
  4. Refresh the comment from the server before allowing an edit to catch deletions.
Defensive patterns

Strategy: try-catch

Validate before calling

function canEditComment(comment: {id: string}, memberId: string | null, editWindowMs: number, createdAt: string): boolean {
  return Boolean(memberId) && Boolean(comment.id)
    && Date.now() - new Date(createdAt).getTime() < editWindowMs;
}

Try / catch

try {
  const result = await api.comments.edit({comment});
} catch (e) {
  if (e instanceof Error && e.message === 'Failed to edit comment') {
    // likely 403 edit window expired or 404 deleted
  }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of TryGhost/Ghost@47d8b0e2ad (2026-08-13). Data as JSON: /api/errors/2857ddbc251c24f5. Report an issue: GitHub.