mirror of
https://github.com/wassname/talk.git
synced 2026-07-08 21:35:38 +08:00
Only use errors from errors.js for EditWindowHasEnded
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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,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.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user