From 892cc7da31f769bba6f2bb9e7c4f3350a22395c8 Mon Sep 17 00:00:00 2001 From: Siteshwar Vashisht Date: Sat, 19 Oct 2013 22:36:18 +0530 Subject: [PATCH] Added a global error handler --- share/tools/web_config/index.html | 2 +- share/tools/web_config/js/app.js | 36 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/share/tools/web_config/index.html b/share/tools/web_config/index.html index 2b93fc8aa..25699e2ac 100644 --- a/share/tools/web_config/index.html +++ b/share/tools/web_config/index.html @@ -94,7 +94,7 @@ function interpret_color(str) {
- fish

+ fish

colors
diff --git a/share/tools/web_config/js/app.js b/share/tools/web_config/js/app.js index 06d386512..296a11c10 100644 --- a/share/tools/web_config/js/app.js +++ b/share/tools/web_config/js/app.js @@ -31,3 +31,39 @@ fishconfig.config( redirectTo: "/colors" }) }]); + +/* Inspired from http://blog.tomaka17.com/2012/12/random-tricks-when-using-angularjs/ */ +fishconfig.config(function($httpProvider, $compileProvider) { + var global_error_element = null; + + var showMessage = function(content) { + global_error_element.text(content); + }; + + $httpProvider.responseInterceptors.push(function($q) { + return function(promise) { + return promise.then(function(successResponse) { + showMessage(''); + return successResponse; + }, function(errorResponse) { + switch (errorResponse.status) { + case 0: + showMessage("The request received an error. Perhaps the server has shut down."); + break; + case 500: + showMessage('Server internal error: ' + errorResponse.data); + break; + default: + showMessage('Error ' + errorResponse.status + ': ' + errorResponse.data); + } + return $q.reject(errorResponse); + }); + }; + }); + + $compileProvider.directive('errorMessage', function() { + return { + link: function(scope, element, attrs) { global_error_element = element; } + }; + }); +});