TryGhost/Ghost · error · Error
Failed to add comment
Error message
Failed to add comment
What it means
comments.add() POSTs a new comment to /members/api/comments with a body of {comments: [comment]}. If the response is not ok, it throws. This is the primary write path for submitting a comment and failures here are typically validation (422) or auth (401) errors.
Source
Thrown at apps/comments-ui/src/utils/api.ts:232
}
},
add({comment}: {comment: AddComment}) {
const body = {
comments: [comment]
};
const url = endpointFor({type: 'members', resource: 'comments'});
return makeRequest({
url,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
}).then(function (res) {
if (res.ok) {
return res.json();
} else {
throw new Error('Failed to add comment');
}
});
},
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();View on GitHub (pinned to 47d8b0e2ad)
Solutions
- Validate the comment body client-side (non-empty, within length limits) before calling add.
- Check the Network tab response body for the 422/401 details to surface a specific message.
- If 401, re-authenticate the member and retry; if 403, inform the user comments may be closed.
- Debounce or rate-limit the submit button to avoid 429s from double-clicks.
Defensive patterns
Strategy: validation
Validate before calling
function isValidCommentBody(html: string): boolean {
const text = html.replace(/<[^>]*>/g, '').trim();
return text.length > 0 && text.length <= 10000;
} Try / catch
try {
const result = await api.comments.add({comment});
} catch (e) {
if (e instanceof Error && e.message === 'Failed to add comment') {
// check member session; show validation/auth error to user
}
} Prevention
- Validate the comment body is non-empty and within length limits before submitting.
- Disable the submit button during the request to prevent double-submits and 429s.
- Re-check the member session is valid before allowing a submit to avoid 401s.
When it happens
Trigger: The POST returns 4xx/5xx. The comment body is empty or fails server-side validation (422), the member is not authenticated (401), the member is banned or lacks comment permissions (403), the post has comments closed (403), or the server rejects the payload schema. Rate limiting (429) on rapid successive posts is also possible.
Common situations: A member submits an empty comment or one exceeding the length limit. A member whose session expired between loading the form and submitting. A post where the author closed comments after the form was opened. Spam protection rejecting the submission.
Related errors
- Failed to edit comment
- Failed to fetch comments
- Failed to read comment
- Failed to fetch site data
- Failed to fetch replies
AI-assisted analysis of TryGhost/Ghost@47d8b0e2ad (2026-08-13).
Data as JSON: /api/errors/35ece7140b110b7e.
Report an issue: GitHub.