From f37a2104790a4f5c3741972f52889b33bf337db0 Mon Sep 17 00:00:00 2001 From: Benjamin Goering Date: Tue, 9 May 2017 15:02:26 -0700 Subject: [PATCH] Only use errors from errors.js for EditWindowHasEnded --- errors.js | 9 ++++++++- graph/mutators/comment.js | 5 ----- services/comments.js | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/errors.js b/errors.js index 67ae0693a..19b0ec90c 100644 --- a/errors.js +++ b/errors.js @@ -153,6 +153,12 @@ const ErrLoginAttemptMaximumExceeded = new APIError('You have made too many inco status: 429 }); +class ErrEditWindowHasEnded extends APIError { + constructor(message) { + super(message || 'Edit window is over.', {status: 403, translation_key: 'error.editWindowExpired'}); + } +} + module.exports = { ExtendableError, APIError, @@ -174,5 +180,6 @@ module.exports = { ErrPermissionUpdateUsername, ErrSettingsInit, ErrInstallLock, - ErrLoginAttemptMaximumExceeded + ErrLoginAttemptMaximumExceeded, + ErrEditWindowHasEnded, }; diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index 17c75a94b..7e5bc3a1b 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -249,11 +249,6 @@ const editComment = async ({user, loaders: {Comments}}, {id, asset_id, edit}) => throw new errors.APIError('Comment not found', { status: 404, translation_key: 'NOT_FOUND', - }); - case 'EditWindowExpired': - throw new errors.APIError('You can no longer edit this comment. The window to do so has expired.', { - status: 401, - translation_key: 'error.editWindowExpired', }); case 'NotAuthorizedToEdit': throw errors.ErrNotAuthorized; diff --git a/services/comments.js b/services/comments.js index 6e3d79edd..002e7b1af 100644 --- a/services/comments.js +++ b/services/comments.js @@ -3,6 +3,8 @@ const CommentModel = require('../models/comment'); const ActionModel = require('../models/action'); const ActionsService = require('./actions'); +const {ErrEditWindowHasEnded} = require('../errors'); + // const ALLOWED_TAGS = [ // {name: 'STAFF'}, // {name: 'BEST'}, @@ -115,9 +117,7 @@ module.exports = class CommentsService { name: 'NotAuthorizedToEdit' }); } else if (( ! ignoreEditWindow) && editWindowExpired(comment)) { - throw Object.assign(new Error('Edit window is over.'), { - name: 'EditWindowExpired' - }); + throw new ErrEditWindowHasEnded(); } throw new Error('Failed to edit comment. This could be because it can\'t be found, the edit window expired, or because you\'re not allowed to edit it.'); }