Only use errors from errors.js for EditWindowHasEnded

This commit is contained in:
Benjamin Goering
2017-05-09 15:02:26 -07:00
parent 096025b72a
commit f37a210479
3 changed files with 11 additions and 9 deletions
+8 -1
View File
@@ -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,
};
-5
View File
@@ -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;
+3 -3
View File
@@ -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.');
}