From fa18301a1813b3e8ed9647baf426b3d16e5cd28a Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Mon, 11 Aug 2014 12:42:33 +0200 Subject: [PATCH] Adding redirect to error page when connection error --- app/coffee/app.coffee | 10 +++++++--- app/partials/error.jade | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 app/partials/error.jade diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index a5fe8813..9c1b201b 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -125,6 +125,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, tgLoade {templateUrl: "/partials/change-password-from-recovery.html"}) $routeProvider.when("/invitation/:token", {templateUrl: "/partials/invitation.html"}) + $routeProvider.when("/error", {templateUrl: "/partials/error.html"}) $routeProvider.otherwise({redirectTo: '/login'}) $locationProvider.html5Mode(true) @@ -141,15 +142,18 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, tgLoade $httpProvider.defaults.headers.get = {} # Add next param when user try to access to a secction need auth permissions. - authHttpIntercept = ($q, $location) -> + authHttpIntercept = ($q, $location, $confirm) -> return (promise) -> return promise.then null, (response) -> - if response.status == 401 or response.status == 0 + if response.status == 0 + $confirm.notify("error", "One of our Oompa Loompas says we are having a network problem. Please, try again in a few moments.") #TODO: i18n + $location.url("/error") + else if response.status == 401 nextPath = $location.path() $location.url("/login").search("next=#{nextPath}") return $q.reject(response) - $provide.factory("authHttpIntercept", ["$q", "$location", authHttpIntercept]) + $provide.factory("authHttpIntercept", ["$q", "$location", "$tgConfirm", authHttpIntercept]) $httpProvider.responseInterceptors.push('authHttpIntercept') $httpProvider.interceptors.push('loaderInterceptor'); diff --git a/app/partials/error.jade b/app/partials/error.jade new file mode 100644 index 00000000..adbbc33a --- /dev/null +++ b/app/partials/error.jade @@ -0,0 +1 @@ +h1 TODO