{"record":{"id":"35ece7140b110b7e","repo":"TryGhost/Ghost","slug":"failed-to-add-comment","errorCode":null,"errorMessage":"Failed to add comment","messagePattern":"Failed to add comment","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/comments-ui/src/utils/api.ts","lineNumber":232,"sourceCode":"                }\n            },\n            add({comment}: {comment: AddComment}) {\n                const body = {\n                    comments: [comment]\n                };\n                const url = endpointFor({type: 'members', resource: 'comments'});\n                return makeRequest({\n                    url,\n                    method: 'POST',\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 add comment');\n                    }\n                });\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();","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/TryGhost/Ghost/blob/47d8b0e2ad2fd4757d3bc45f46c3ac165ff8a1fe/apps/comments-ui/src/utils/api.ts#L214-L250","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function isValidCommentBody(html: string): boolean {\n  const text = html.replace(/<[^>]*>/g, '').trim();\n  return text.length > 0 && text.length <= 10000;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const result = await api.comments.add({comment});\n} catch (e) {\n  if (e instanceof Error && e.message === 'Failed to add comment') {\n    // check member session; show validation/auth error to user\n  }\n}","preventionTips":["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."],"tags":["network","fetch","comments-ui","comments","create","write"],"backgroundTag":null,"analyzedSha":"47d8b0e2ad2fd4757d3bc45f46c3ac165ff8a1fe","analyzedAt":"2026-08-13T01:25:26.651Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}