diff --git a/client/coral-framework/translations.json b/client/coral-framework/translations.json index f2b0ad1cc..2e4c405b4 100644 --- a/client/coral-framework/translations.json +++ b/client/coral-framework/translations.json @@ -33,6 +33,7 @@ "unexpectedError": "Unexpected error while saving changes. Sorry!" }, "error": { + "COMMENT_TOO_SHORT": "Your comment must have something in it", "EDIT_WINDOW_ENDED": "You can no longer edit this comment. The time window to do so has expired.", "emailNotVerified": "Email address {0} not verified.", "email": "Not a valid E-Mail", diff --git a/errors.js b/errors.js index 94bed0d12..c203b1d25 100644 --- a/errors.js +++ b/errors.js @@ -162,6 +162,12 @@ const ErrEditWindowHasEnded = new APIError('Edit window is over', { status: 403 }); +// ErrCommentTooShort is returned when the comment is too short. +const ErrCommentTooShort = new APIError('Comment was too short', { + translation_key: 'COMMENT_TOO_SHORT', + status: 400 +}); + module.exports = { ExtendableError, APIError, @@ -185,4 +191,5 @@ module.exports = { ErrInstallLock, ErrLoginAttemptMaximumExceeded, ErrEditWindowHasEnded, + ErrCommentTooShort }; diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index aa113e54b..fd1949e43 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -85,6 +85,11 @@ const filterNewComment = (context, {body, asset_id}) => { */ const resolveNewCommentStatus = async (context, {asset_id, body}, wordlist = {}, settings = {}) => { + // Check to see if the body is too short, if it is, then complain about it! + if (body.length < 2) { + throw errors.ErrCommentTooShort; + } + // Decide the status based on whether or not the current asset/settings // has pre-mod enabled or not. If the comment was rejected based on the // wordlist, then reject it, otherwise if the moderation setting is