GUACAMOLE-526: Add convenience callback for displaying modal notifications strictly for REST errors, while logging all other promise rejections.

This commit is contained in:
Michael Jumper
2018-04-26 21:20:31 -07:00
parent 1e5e9b607b
commit f6d5e5662b
2 changed files with 20 additions and 3 deletions

View File

@@ -21,4 +21,7 @@
* The module for code relating to communication with the REST API of the * The module for code relating to communication with the REST API of the
* Guacamole web application. * Guacamole web application.
*/ */
angular.module('rest', ['auth']); angular.module('rest', [
'auth',
'notification'
]);

View File

@@ -25,8 +25,9 @@ angular.module('rest').factory('requestService', ['$injector',
function requestService($injector) { function requestService($injector) {
// Required services // Required services
var $http = $injector.get('$http'); var $http = $injector.get('$http');
var $log = $injector.get('$log'); var $log = $injector.get('$log');
var guacNotification = $injector.get('guacNotification');
// Required types // Required types
var Error = $injector.get('Error'); var Error = $injector.get('Error');
@@ -115,6 +116,19 @@ angular.module('rest').factory('requestService', ['$injector',
$log.warn(error.type, error.message || error.translatableMessage); $log.warn(error.type, error.message || error.translatableMessage);
}); });
/**
* Promise error callback which displays a modal notification for all
* rejections due to REST errors. The message displayed to the user within
* the notification is provided by the contents of the @link{Error} object
* within the REST response. All other rejections, such as those due to
* JavaScript errors, are logged to the browser console without displaying
* any notification.
*
* @constant
* @type Function
*/
service.SHOW_NOTIFICATION = service.createErrorCallback(guacNotification.showRequestError);
return service; return service;
}]); }]);