diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2018-03-19 15:36:08 +0100 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2018-03-20 19:09:04 +0100 |
commit | 1c440519c2653323dd49fb4ec3a06851d114c4fe (patch) | |
tree | d744a4fe5dfd3634185d4d724fdedc32e3a71584 /core/js | |
parent | ed1452d7a067d383371dcd165ad86e01f174840b (diff) | |
download | nextcloud-server-1c440519c2653323dd49fb4ec3a06851d114c4fe.tar.gz nextcloud-server-1c440519c2653323dd49fb4ec3a06851d114c4fe.zip |
Show an error when getting the suggestions succeeds with failure content
Instead of silently failing now an error is shown to the user when the
ajax call to get the suggestions succeeds yet it returns failure content
(for example, if an "OCSBadRequestException" was thrown in the server).
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/sharedialogview.js | 17 | ||||
-rw-r--r-- | core/js/tests/specs/sharedialogviewSpec.js | 9 |
2 files changed, 16 insertions, 10 deletions
diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 9e3de2636ce..7c31239d4a1 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -242,7 +242,7 @@ deferred.resolve(suggestions); } else { - deferred.resolve(null); + deferred.reject(result.ocs.meta.message); } } ).fail(function() { @@ -296,7 +296,7 @@ $loading.removeClass('inlineblock'); $confirm.removeClass('hidden'); - if (suggestions && suggestions.length > 0) { + if (suggestions.length > 0) { $shareWithField .autocomplete("option", "autoFocus", true); @@ -312,7 +312,7 @@ $('.ui-autocomplete').append('<li class="autocomplete-note">' + message + '</li>'); } - } else if (suggestions) { + } else { var title = t('core', 'No users or groups found for {search}', {search: $shareWithField.val()}); if (!view.configModel.get('allowGroupSharing')) { title = t('core', 'No users found for {search}', {search: $('.shareWithField').val()}); @@ -327,14 +327,17 @@ .tooltip('fixTitle') .tooltip('show'); response(); - } else { - response(); } - }).fail(function() { + }).fail(function(message) { $loading.addClass('hidden'); $loading.removeClass('inlineblock'); $confirm.removeClass('hidden'); - OC.Notification.showTemporary(t('core', 'An error occurred. Please try again')); + + if (message) { + OC.Notification.showTemporary(t('core', 'An error occurred ("{message}"). Please try again', { message: message })); + } else { + OC.Notification.showTemporary(t('core', 'An error occurred. Please try again')); + } }); }, diff --git a/core/js/tests/specs/sharedialogviewSpec.js b/core/js/tests/specs/sharedialogviewSpec.js index c12c734a5df..be1aa4c9a8e 100644 --- a/core/js/tests/specs/sharedialogviewSpec.js +++ b/core/js/tests/specs/sharedialogviewSpec.js @@ -1462,7 +1462,7 @@ describe('OC.Share.ShareDialogView', function() { }); }); - it('gracefully handles successful ajax call with failure content', function () { + it('throws a notification for a successful ajax call with failure content', function () { dialog.render(); var response = sinon.stub(); dialog.autocompleteHandler({term: 'bob'}, response); @@ -1470,7 +1470,8 @@ describe('OC.Share.ShareDialogView', function() { 'ocs' : { 'meta' : { 'status': 'failure', - 'statuscode': 400 + 'statuscode': 400, + 'message': 'error message' } } }); @@ -1479,7 +1480,9 @@ describe('OC.Share.ShareDialogView', function() { {'Content-Type': 'application/json'}, jsonData ); - expect(response.calledWithExactly()).toEqual(true); + expect(response.called).toEqual(false); + expect(showTemporaryNotificationStub.calledOnce).toEqual(true); + expect(showTemporaryNotificationStub.firstCall.args[0]).toContain('error message'); }); it('throws a notification when the ajax search lookup fails', function () { |