Add convenience promise callback for REST requests which displays a fatal error.
@@ -27,6 +27,7 @@ angular.module('rest').factory('requestService', ['$injector',
// Required services
var $http = $injector.get('$http');
var $log = $injector.get('$log');
+ var $rootScope = $injector.get('$rootScope');
// Required types
var Error = $injector.get('Error');
@@ -115,6 +116,21 @@ angular.module('rest').factory('requestService', ['$injector',
$log.warn(error.type, error.message || error.translatableMessage);
});
+ /**
+ * Promise error callback which replaces the content of the page with a
+ * generic error message warning that the page could not be displayed. All
+ * rejections are logged to the browser console as errors. This callback
+ * should be used in favor of @link{WARN} if REST errors will result in the
+ * page being unusable.
+ *
+ * @constant
+ * @type Function
+ */
+ service.DIE = service.createErrorCallback(function fatalPageError(error) {
+ $rootScope.$broadcast('guacFatalPageError', error);
+ $log.error(error.type, error.message || error.translatableMessage);
+ });
+
return service;
}]);
