From f6d5e5662b643e0521a3069c14639ca03a9a0714 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 26 Apr 2018 21:20:31 -0700 Subject: [PATCH] GUACAMOLE-526: Add convenience callback for displaying modal notifications strictly for REST errors, while logging all other promise rejections. --- .../src/main/webapp/app/rest/restModule.js | 5 ++++- .../webapp/app/rest/services/requestService.js | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/guacamole/src/main/webapp/app/rest/restModule.js b/guacamole/src/main/webapp/app/rest/restModule.js index 81b64b53d..6672507dc 100644 --- a/guacamole/src/main/webapp/app/rest/restModule.js +++ b/guacamole/src/main/webapp/app/rest/restModule.js @@ -21,4 +21,7 @@ * The module for code relating to communication with the REST API of the * Guacamole web application. */ -angular.module('rest', ['auth']); +angular.module('rest', [ + 'auth', + 'notification' +]); diff --git a/guacamole/src/main/webapp/app/rest/services/requestService.js b/guacamole/src/main/webapp/app/rest/services/requestService.js index 9aef12486..a27ccc3bb 100644 --- a/guacamole/src/main/webapp/app/rest/services/requestService.js +++ b/guacamole/src/main/webapp/app/rest/services/requestService.js @@ -25,8 +25,9 @@ angular.module('rest').factory('requestService', ['$injector', function requestService($injector) { // Required services - var $http = $injector.get('$http'); - var $log = $injector.get('$log'); + var $http = $injector.get('$http'); + var $log = $injector.get('$log'); + var guacNotification = $injector.get('guacNotification'); // Required types var Error = $injector.get('Error'); @@ -115,6 +116,19 @@ angular.module('rest').factory('requestService', ['$injector', $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; }]);