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>
This commit is contained in:
Daniel Calviño Sánchez 2018-03-19 15:36:08 +01:00
parent ed1452d7a0
commit 1c440519c2
2 changed files with 16 additions and 10 deletions

View File

@ -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'));
}
});
},

View File

@ -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 () {