From 56ad4cdfec41f5b3dbbca357b4730f7db1700b1e Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 24 Jun 2016 10:10:10 +0200 Subject: Show error message when posting an invalid comment When an internal server error occurs while creating or updating a comment, display a proper error notification in the UI. --- apps/comments/js/commentstabview.js | 12 ++++++------ apps/dav/lib/Comments/CommentNode.php | 2 +- apps/dav/tests/unit/Comments/CommentsNodeTest.php | 6 +++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/comments/js/commentstabview.js b/apps/comments/js/commentstabview.js index 9475dc53fc0..f71567f04d1 100644 --- a/apps/comments/js/commentstabview.js +++ b/apps/comments/js/commentstabview.js @@ -337,10 +337,10 @@ $comment.data('commentEl').remove(); $comment.remove(); }, - error: function(msg) { + error: function() { $loading.addClass('hidden'); $comment.removeClass('disabled'); - OC.Notification.showTemporary(msg); + OC.Notification.showTemporary(t('comments', 'Error occurred while retrieving comment with id {id}', {id: commentId})); } }); @@ -388,12 +388,12 @@ .html(self._formatMessage(model.get('message'))); $row.remove(); }, - error: function(msg) { + error: function() { $submit.removeClass('hidden'); $loading.addClass('hidden'); $textArea.prop('disabled', false); - OC.Notification.showTemporary(msg); + OC.Notification.showTemporary(t('comments', 'Error occurred while updating comment with id {id}', {id: commentId})); } }); } else { @@ -413,12 +413,12 @@ $loading.addClass('hidden'); $textArea.val('').prop('disabled', false); }, - error: function(msg) { + error: function() { $submit.removeClass('hidden'); $loading.addClass('hidden'); $textArea.prop('disabled', false); - OC.Notification.showTemporary(msg); + OC.Notification.showTemporary(t('comments', 'Error occurred while posting comment')); } }); } diff --git a/apps/dav/lib/Comments/CommentNode.php b/apps/dav/lib/Comments/CommentNode.php index edf46d210fc..5c22f8a8a71 100644 --- a/apps/dav/lib/Comments/CommentNode.php +++ b/apps/dav/lib/Comments/CommentNode.php @@ -185,7 +185,7 @@ class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties { $msg = 'Message exceeds allowed character limit of '; throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); } - return false; + throw $e; } } diff --git a/apps/dav/tests/unit/Comments/CommentsNodeTest.php b/apps/dav/tests/unit/Comments/CommentsNodeTest.php index 6bf06375a43..18b18ab8d3b 100644 --- a/apps/dav/tests/unit/Comments/CommentsNodeTest.php +++ b/apps/dav/tests/unit/Comments/CommentsNodeTest.php @@ -166,6 +166,10 @@ class CommentsNodeTest extends \Test\TestCase { $this->assertTrue($this->node->updateComment($msg)); } + /** + * @expectedException Exception + * @expectedExceptionMessage buh! + */ public function testUpdateCommentLogException() { $msg = null; @@ -198,7 +202,7 @@ class CommentsNodeTest extends \Test\TestCase { $this->logger->expects($this->once()) ->method('logException'); - $this->assertFalse($this->node->updateComment($msg)); + $this->node->updateComment($msg); } /** -- cgit v1.2.3