add interceptor to handle version errors
parent
a8caf6dae0
commit
7a6f689004
|
@ -161,7 +161,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
|
|||
$tgEventsProvider.setSessionId(taiga.sessionId)
|
||||
|
||||
# Add next param when user try to access to a secction need auth permissions.
|
||||
authHttpIntercept = ($q, $location, $confirm, $navUrls, $lightboxService) ->
|
||||
authHttpIntercept = ($q, $location, $navUrls, $lightboxService) ->
|
||||
httpResponseError = (response) ->
|
||||
if response.status == 0
|
||||
$lightboxService.closeAll()
|
||||
|
@ -170,17 +170,37 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
|
|||
else if response.status == 401
|
||||
nextPath = $location.path()
|
||||
$location.url($navUrls.resolve("login")).search("next=#{nextPath}")
|
||||
|
||||
return $q.reject(response)
|
||||
|
||||
return {
|
||||
responseError: httpResponseError
|
||||
}
|
||||
|
||||
$provide.factory("authHttpIntercept", ["$q", "$location", "$tgConfirm", "$tgNavUrls",
|
||||
"lightboxService", authHttpIntercept])
|
||||
$provide.factory("authHttpIntercept", ["$q", "$location", "$tgNavUrls", "lightboxService", authHttpIntercept])
|
||||
|
||||
$httpProvider.interceptors.push('authHttpIntercept');
|
||||
|
||||
# If there is an error in the version throw a notify error
|
||||
versionCheckHttpIntercept = ($q, $confirm) ->
|
||||
versionErrorMsg = "Someone inside Taiga has changed this before and our Oompa Loompas cannot apply your changes. Please reload and apply your changes again (they will be lost)." #TODO: i18n
|
||||
|
||||
httpResponseError = (response) ->
|
||||
if response.status == 400 && response.data.version
|
||||
$confirm.notify("error", versionErrorMsg, null, 10000)
|
||||
|
||||
return $q.reject(response)
|
||||
|
||||
return $q.reject(response)
|
||||
|
||||
return {
|
||||
responseError: httpResponseError
|
||||
}
|
||||
|
||||
$provide.factory("versionCheckHttpIntercept", ["$q", "$tgConfirm", versionCheckHttpIntercept])
|
||||
|
||||
$httpProvider.interceptors.push('versionCheckHttpIntercept');
|
||||
|
||||
window.checksley.updateValidators({
|
||||
linewidth: (val, width) ->
|
||||
lines = taiga.nl2br(val).split("<br />")
|
||||
|
|
|
@ -170,7 +170,7 @@ class ConfirmService extends taiga.Service
|
|||
|
||||
return defered.promise
|
||||
|
||||
notify: (type, message, title) ->
|
||||
notify: (type, message, title, time) ->
|
||||
# NOTE: Typesi are: error, success, light-error
|
||||
# See partials/components/notification-message.jade)
|
||||
# Add default texts to NOTIFICATION_MSG for new notification types
|
||||
|
@ -178,6 +178,8 @@ class ConfirmService extends taiga.Service
|
|||
selector = ".notification-message-#{type}"
|
||||
el = angular.element(selector)
|
||||
|
||||
return if el.hasClass("active")
|
||||
|
||||
if title
|
||||
el.find("h4").html(title)
|
||||
else
|
||||
|
@ -200,7 +202,8 @@ class ConfirmService extends taiga.Service
|
|||
if @.tsem
|
||||
cancelTimeout(@.tsem)
|
||||
|
||||
time = if type == 'error' or type == 'light-error' then 3500 else 1500
|
||||
if !time
|
||||
time = if type == 'error' or type == 'light-error' then 3500 else 1500
|
||||
|
||||
@.tsem = timeout time, =>
|
||||
body.find(selector)
|
||||
|
|
Loading…
Reference in New Issue