Don't redirect on errors

- not-found
- error
- permissions
- blocked
stable
Juanfran 2016-05-13 11:51:52 +02:00 committed by Alejandro Alonso
parent 5f435ff882
commit b69622cd5b
26 changed files with 161 additions and 102 deletions

View File

@ -6,6 +6,7 @@
### Features
- Show a confirmation notice when you exit edit mode by pressing ESC in the markdown inputs.
- Add the tribe button to link stories from tree.taiga.io with gigs in tribe.taiga.io.
- Errors (not found, server error, permissions and blocked project) don't change the current url.
### Misc
- Lots of small and not so small bugfixes.

View File

@ -443,7 +443,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
$routeProvider.when("/permission-denied",
{templateUrl: "error/permission-denied.html"})
$routeProvider.otherwise({redirectTo: "/not-found"})
$routeProvider.otherwise({templateUrl: "error/not-found.html"})
$locationProvider.html5Mode({enabled: true, requireBase: false})
defaultHeaders = {
@ -465,12 +465,12 @@ 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, $navUrls, $lightboxService) ->
authHttpIntercept = ($q, $location, $navUrls, $lightboxService, errorHandlingService) ->
httpResponseError = (response) ->
if response.status == 0 || (response.status == -1 && !response.config.cancelable)
$lightboxService.closeAll()
$location.path($navUrls.resolve("error"))
$location.replace()
errorHandlingService.error()
else if response.status == 401 and $location.url().indexOf('/login') == -1
nextUrl = encodeURIComponent($location.url())
$location.url($navUrls.resolve("login")).search("next=#{nextUrl}")
@ -481,7 +481,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
responseError: httpResponseError
}
$provide.factory("authHttpIntercept", ["$q", "$location", "$tgNavUrls", "lightboxService",
$provide.factory("authHttpIntercept", ["$q", "$location", "$tgNavUrls", "lightboxService", "tgErrorHandlingService",
authHttpIntercept])
$httpProvider.interceptors.push("authHttpIntercept")
@ -536,7 +536,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
$httpProvider.interceptors.push("versionCheckHttpIntercept")
blockingIntercept = ($q, $routeParams, $location, $navUrls) ->
blockingIntercept = ($q, $routeParams, $location, $navUrls, errorHandlingService) ->
# API calls can return blocked elements and in that situation the user will be redirected
# to the blocked project page
# This can happens in two scenarios
@ -544,10 +544,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
# - An error reponse when updating/creating/deleting including a 451 error code
redirectToBlockedPage = ->
pslug = $routeParams.pslug
blockedUrl = $navUrls.resolve("blocked-project", {project: pslug})
currentUrl = $location.url()
if currentUrl.indexOf(blockedUrl) == -1
$location.replace().path(blockedUrl)
errorHandlingService.block()
responseOk = (response) ->
if response.data.blocked_code
@ -566,7 +563,7 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
responseError: responseError
}
$provide.factory("blockingIntercept", ["$q", "$routeParams", "$location", "$tgNavUrls", blockingIntercept])
$provide.factory("blockingIntercept", ["$q", "$routeParams", "$location", "$tgNavUrls", "tgErrorHandlingService", blockingIntercept])
$httpProvider.interceptors.push("blockingIntercept")
@ -637,7 +634,7 @@ i18nInit = (lang, $translate) ->
checksley.updateMessages('default', messages)
init = ($log, $rootscope, $auth, $events, $analytics, $translate, $location, $navUrls, appMetaService, projectService, loaderService, navigationBarService) ->
init = ($log, $rootscope, $auth, $events, $analytics, $translate, $location, $navUrls, appMetaService, projectService, loaderService, navigationBarService, errorHandlingService) ->
$log.debug("Initialize application")
$rootscope.$on '$translatePartialLoaderStructureChanged', () ->
@ -691,6 +688,8 @@ init = ($log, $rootscope, $auth, $events, $analytics, $translate, $location, $na
un()
$rootscope.$on '$routeChangeSuccess', (event, next) ->
errorHandlingService.init()
if next.loader
loaderService.start(true)
@ -803,6 +802,6 @@ module.run([
"tgProjectService",
"tgLoader",
"tgNavigationBarService",
"$route",
"tgErrorHandlingService",
init
])

View File

@ -28,11 +28,9 @@ class TaigaController extends TaigaBase
onInitialDataError: (xhr) =>
if xhr
if xhr.status == 404
@location.path(@navUrls.resolve("not-found"))
@location.replace()
@errorHandlingService.notfound()
else if xhr.status == 403
@location.path(@navUrls.resolve("permission-denied"))
@location.replace()
@errorHandlingService.permissionDenied()
return @q.reject(xhr)

View File

@ -48,12 +48,13 @@ class MembershipsController extends mixOf(taiga.Controller, taiga.PageMixin, tai
"$tgAnalytics",
"tgAppMetaService",
"$translate",
"$tgAuth"
"tgLightboxFactory"
"$tgAuth",
"tgLightboxFactory",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @navUrls, @analytics,
@appMetaService, @translate, @auth, @lightboxFactory) ->
@appMetaService, @translate, @auth, @lightboxFactory, @errorHandlingService) ->
bindMethods(@)
@scope.project = {}
@ -75,7 +76,7 @@ class MembershipsController extends mixOf(taiga.Controller, taiga.PageMixin, tai
loadProject: ->
return @rs.projects.getBySlug(@params.pslug).then (project) =>
if not project.i_am_admin
@location.path(@navUrls.resolve("permission-denied"))
@errorHandlingService.permissionDenied()
@scope.projectId = project.id
@scope.project = project

View File

@ -53,11 +53,12 @@ class ProjectProfileController extends mixOf(taiga.Controller, taiga.PageMixin)
"tgAppMetaService",
"$translate",
"$tgAuth",
"tgCurrentUserService"
"tgCurrentUserService",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @navUrls,
@appMetaService, @translate, @tgAuth, @currentUserService) ->
@appMetaService, @translate, @tgAuth, @currentUserService, @errorHandlingService) ->
@scope.project = {}
promise = @.loadInitialData()
@ -83,7 +84,7 @@ class ProjectProfileController extends mixOf(taiga.Controller, taiga.PageMixin)
loadProject: ->
return @rs.projects.getBySlug(@params.pslug).then (project) =>
if not project.i_am_admin
@location.path(@navUrls.resolve("permission-denied"))
@errorHandlingService.permissionDenied()
@scope.projectId = project.id
@scope.project = project

View File

@ -50,11 +50,12 @@ class ProjectValuesSectionController extends mixOf(taiga.Controller, taiga.PageM
"$tgLocation",
"$tgNavUrls",
"tgAppMetaService",
"$translate"
"$translate",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @navUrls,
@appMetaService, @translate) ->
@appMetaService, @translate, @errorHandlingService) ->
@scope.project = {}
promise = @.loadInitialData()
@ -74,7 +75,7 @@ class ProjectValuesSectionController extends mixOf(taiga.Controller, taiga.PageM
loadProject: ->
return @rs.projects.getBySlug(@params.pslug).then (project) =>
if not project.i_am_admin
@location.path(@navUrls.resolve("permission-denied"))
@errorHandlingService.permissionDenied()
@scope.projectId = project.id
@scope.project = project

View File

@ -48,11 +48,12 @@ class RolesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fil
"$tgLocation",
"$tgNavUrls",
"tgAppMetaService",
"$translate"
"$translate",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @navUrls,
@appMetaService, @translate) ->
@appMetaService, @translate, @errorHandlingService) ->
bindMethods(@)
@scope.sectionName = "ADMIN.MENU.PERMISSIONS"
@ -71,7 +72,7 @@ class RolesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fil
loadProject: ->
return @rs.projects.getBySlug(@params.pslug).then (project) =>
if not project.i_am_admin
@location.path(@navUrls.resolve("permission-denied"))
@errorHandlingService.permissionDenied()
@scope.projectId = project.id
@scope.project = project

View File

@ -45,10 +45,11 @@ class WebhooksController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.
"$tgLocation",
"$tgNavUrls",
"tgAppMetaService",
"$translate"
"$translate",
"tgErrorHandlingService"
]
constructor: (@scope, @repo, @rs, @params, @location, @navUrls, @appMetaService, @translate) ->
constructor: (@scope, @repo, @rs, @params, @location, @navUrls, @appMetaService, @translate, @errorHandlingService) ->
bindMethods(@)
@scope.sectionName = "ADMIN.WEBHOOKS.SECTION_NAME"
@ -72,7 +73,7 @@ class WebhooksController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.
loadProject: ->
return @rs.projects.getBySlug(@params.pslug).then (project) =>
if not project.i_am_admin
@location.path(@navUrls.resolve("permission-denied"))
@errorHandlingService.permissionDenied()
@scope.projectId = project.id
@scope.project = project

View File

@ -56,11 +56,12 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
"$translate",
"$tgLoading",
"tgResources",
"$tgQueueModelTransformation"
"$tgQueueModelTransformation",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q,
@location, @appMetaService, @navUrls, @events, @analytics, @translate, @loading, @rs2, @modelTransform) ->
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @appMetaService, @navUrls,
@events, @analytics, @translate, @loading, @rs2, @modelTransform, @errorHandlingService) ->
bindMethods(@)
@.page = 1
@ -317,7 +318,7 @@ class BacklogController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.F
loadProject: ->
return @rs.projects.getBySlug(@params.pslug).then (project) =>
if not project.is_backlog_activated
@location.path(@navUrls.resolve("permission-denied"))
@errorHandlingService.permissionDenied()
@scope.projectId = project.id
@scope.project = project

View File

@ -52,11 +52,12 @@ class IssueDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
"$tgAnalytics",
"$tgNavUrls",
"$translate",
"$tgQueueModelTransformation"
"$tgQueueModelTransformation",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location,
@log, @appMetaService, @analytics, @navUrls, @translate, @modelTransform) ->
@log, @appMetaService, @analytics, @navUrls, @translate, @modelTransform, @errorHandlingService) ->
bindMethods(@)
@scope.issueRef = @params.issueref

View File

@ -54,11 +54,12 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
"$tgNavUrls",
"$tgEvents",
"$tgAnalytics",
"$translate"
"$translate",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @urls, @params, @q, @location, @appMetaService,
@navUrls, @events, @analytics, @translate) ->
@navUrls, @events, @analytics, @translate, @errorHandlingService) ->
@scope.sectionName = "Issues"
@scope.filters = {}
@ -98,7 +99,7 @@ class IssuesController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
loadProject: ->
return @rs.projects.getBySlug(@params.pslug).then (project) =>
if not project.is_issues_activated
@location.path(@navUrls.resolve("permission-denied"))
@errorHandlingService.permissionDenied()
@scope.projectId = project.id
@scope.project = project

View File

@ -61,11 +61,12 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
"$tgNavUrls",
"$tgEvents",
"$tgAnalytics",
"$translate"
"$translate",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location,
@appMetaService, @navUrls, @events, @analytics, @translate) ->
@appMetaService, @navUrls, @events, @analytics, @translate, @errorHandlingService) ->
bindMethods(@)
@ -193,7 +194,7 @@ class KanbanController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
loadProject: ->
return @rs.projects.getBySlug(@params.pslug).then (project) =>
if not project.is_kanban_activated
@location.path(@navUrls.resolve("permission-denied"))
@errorHandlingService.permissionDenied()
@scope.projectId = project.id
@scope.project = project

View File

@ -48,10 +48,11 @@ class SearchController extends mixOf(taiga.Controller, taiga.PageMixin)
"$tgLocation",
"tgAppMetaService",
"$tgNavUrls",
"$translate"
"$translate",
"tgErrorHandlingService"
]
constructor: (@scope, @repo, @rs, @params, @q, @location, @appMetaService, @navUrls, @translate) ->
constructor: (@scope, @repo, @rs, @params, @q, @location, @appMetaService, @navUrls, @translate, @errorHandlingService) ->
@scope.sectionName = "Search"
promise = @.loadInitialData()

View File

@ -52,11 +52,12 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin)
"$tgNavUrls"
"$tgEvents"
"$tgAnalytics",
"$translate"
"$translate",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @appMetaService, @location, @navUrls,
@events, @analytics, @translate) ->
@events, @analytics, @translate, @errorHandlingService) ->
bindMethods(@)
@scope.sectionName = @translate.instant("TASKBOARD.SECTION_NAME")
@ -124,7 +125,7 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin)
loadProject: ->
return @rs.projects.get(@scope.projectId).then (project) =>
if not project.is_backlog_activated
@location.path(@navUrls.resolve("permission-denied"))
@errorHandlingService.permissionDenied()
@scope.project = project
# Not used at this momment

View File

@ -50,11 +50,12 @@ class TaskDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
"$tgNavUrls",
"$tgAnalytics",
"$translate",
"$tgQueueModelTransformation"
"$tgQueueModelTransformation",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location,
@log, @appMetaService, @navUrls, @analytics, @translate, @modelTransform) ->
@log, @appMetaService, @navUrls, @analytics, @translate, @modelTransform, @errorHandlingService) ->
bindMethods(@)
@scope.taskRef = @params.taskref

View File

@ -45,11 +45,12 @@ class TeamController extends mixOf(taiga.Controller, taiga.PageMixin)
"tgAppMetaService",
"$tgAuth",
"$translate",
"tgProjectService"
"tgProjectService",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @repo, @rs, @params, @q, @location, @navUrls, @appMetaService, @auth,
@translate, @projectService) ->
@translate, @projectService, @errorHandlingService) ->
@scope.sectionName = "TEAM.SECTION_NAME"
promise = @.loadInitialData()

View File

@ -45,19 +45,19 @@ class UserSettingsController extends mixOf(taiga.Controller, taiga.PageMixin)
"$tgLocation",
"$tgNavUrls",
"$tgAuth",
"$translate"
"$translate",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @config, @repo, @confirm, @rs, @params, @q, @location, @navUrls,
@auth, @translate) ->
@auth, @translate, @errorHandlingService) ->
@scope.sectionName = "USER_SETTINGS.MENU.SECTION_TITLE"
@scope.project = {}
@scope.user = @auth.getUser()
if !@scope.user
@location.path(@navUrls.resolve("permission-denied"))
@location.replace()
@errorHandlingService.permissionDenied()
@scope.lang = @getLan()
@scope.theme = @getTheme()

View File

@ -44,10 +44,11 @@ class UserNotificationsController extends mixOf(taiga.Controller, taiga.PageMixi
"$q",
"$tgLocation",
"$tgNavUrls",
"$tgAuth"
"$tgAuth",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @navUrls, @auth) ->
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @navUrls, @auth, @errorHandlingService) ->
@scope.sectionName = "USER_SETTINGS.NOTIFICATIONS.SECTION_NAME"
@scope.user = @auth.getUser()
promise = @.loadInitialData()

View File

@ -50,12 +50,13 @@ class UserStoryDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
"$tgNavUrls",
"$tgAnalytics",
"$translate",
"$tgConfig",
"$tgQueueModelTransformation"
"$tgQueueModelTransformation",
"tgErrorHandlingService",
"$tgConfig"
]
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location, @log, @appMetaService,
@navUrls, @analytics, @translate, @configService, @modelTransform) ->
constructor: (@scope, @rootscope, @repo, @confirm, @rs, @params, @q, @location,
@log, @appMetaService, @navUrls, @analytics, @translate, @modelTransform, @errorHandlingService, @configService) ->
bindMethods(@)
@scope.usRef = @params.usref

View File

@ -51,11 +51,12 @@ class WikiDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
"tgAppMetaService",
"$tgNavUrls",
"$tgAnalytics",
"$translate"
"$translate",
"tgErrorHandlingService"
]
constructor: (@scope, @rootscope, @repo, @model, @confirm, @rs, @params, @q, @location,
@filter, @log, @appMetaService, @navUrls, @analytics, @translate) ->
@filter, @log, @appMetaService, @navUrls, @analytics, @translate, @errorHandlingService) ->
@scope.projectSlug = @params.pslug
@scope.wikiSlug = @params.slug
@scope.wikiTitle = @scope.wikiSlug
@ -86,7 +87,7 @@ class WikiDetailController extends mixOf(taiga.Controller, taiga.PageMixin)
loadProject: ->
return @rs.projects.getBySlug(@params.pslug).then (project) =>
if not project.is_wiki_activated
@location.path(@navUrls.resolve("permission-denied"))
@errorHandlingService.permissionDenied()
@scope.projectId = project.id
@scope.project = project

View File

@ -20,9 +20,13 @@ html(lang="en")
window.prerenderReady = false;
body(tg-main)
div(tg-navigation-bar)
div(tg-navigation-bar, ng-if="!errorHandling.showingError")
div.master(ng-view, ng-if="!errorHandling.showingError")
div.master(ng-view)
div(ng-if="errorHandling.notfound", ng-include="'error/not-found.html'")
div(ng-if="errorHandling.error", ng-include="'error/error.html'")
div(ng-if="errorHandling.permissionDenied", ng-include="'error/permission-denied.html'")
div(ng-if="errorHandling.blocked", ng-include="'projects/project/blocked-project.html'")
div.lightbox.lightbox-generic-ask
include partials/includes/modules/lightbox-generic-ask

View File

@ -28,10 +28,11 @@ class TransferProject
"tgCurrentUserService",
"$tgNavUrls",
"$translate",
"$tgConfirm"
"$tgConfirm",
"tgErrorHandlingService"
]
constructor: (@routeParams, @projectService, @location, @authService, @currentUserService, @navUrls, @translate, @confirmService) ->
constructor: (@routeParams, @projectService, @location, @authService, @currentUserService, @navUrls, @translate, @confirmService, @errorHandlingService) ->
initialize: () ->
@.projectId = @.project.get("id")
@ -41,7 +42,7 @@ class TransferProject
_validateToken: () ->
return @projectService.transferValidateToken(@.projectId, @.token).then null, (data, status) =>
@location.path(@navUrls.resolve("not-found"))
@errorHandlingService.notfound()
_refreshUserData: () ->
return @authService.refresh().then () =>

View File

@ -28,6 +28,13 @@ describe "TransferProject", ->
mocks.routeParams = {}
provide.value "$routeParams", mocks.routeParams
_mockErrorHandlingService = () ->
mocks.errorHandlingService = {
notfound: sinon.stub()
}
provide.value "tgErrorHandlingService", mocks.errorHandlingService
_mockProjectsService = () ->
mocks.projectsService = {
transferValidateToken: sinon.stub()
@ -90,6 +97,7 @@ describe "TransferProject", ->
_mockTgNavUrls()
_mockTranslate()
_mockTgConfirm()
_mockErrorHandlingService()
return null
_inject = (callback) ->
@ -119,7 +127,7 @@ describe "TransferProject", ->
ctrl = $controller("TransferProjectController")
ctrl.project = project
ctrl.initialize().then () ->
expect(mocks.location.path).to.be.calledWith("/not-found")
expect(mocks.errorHandlingService.notfound).have.been.called;
done()
it "valid token private project with max projects for user", (done) ->

View File

@ -0,0 +1,48 @@
###
# Copyright (C) 2014-2016 Taiga Agile LLC <taiga@taiga.io>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# File: error-handling.service.coffee
###
taiga = @.taiga
class ErrorHandlingService
@.$inject = [
"$rootScope"
]
constructor: (@rootScope) ->
init: () ->
@rootScope.errorHandling = {};
notfound: ->
@rootScope.errorHandling.showingError = true
@rootScope.errorHandling.notfound = true
error: ->
@rootScope.errorHandling.showingError = true
@rootScope.errorHandling.error = true
permissionDenied: ->
@rootScope.errorHandling.showingError = true
@rootScope.errorHandling.permissionDenied = true
block: ->
@rootScope.errorHandling.showingError = true
@rootScope.errorHandling.blocked = true
angular.module("taigaCommon").service("tgErrorHandlingService", ErrorHandlingService)

View File

@ -20,19 +20,16 @@
class xhrError extends taiga.Service
@.$inject = [
"$q",
"$location",
"$tgNavUrls"
"tgErrorHandlingService"
]
constructor: (@q, @location, @navUrls) ->
constructor: (@q, @errorHandlingService) ->
notFound: () ->
@location.path(@navUrls.resolve("not-found"))
@location.replace()
@errorHandlingService.notfound()
permissionDenied: () ->
@location.path(@navUrls.resolve("permission-denied"))
@location.replace()
@errorHandlingService.permissionDenied()
response: (xhr) ->
if xhr

View File

@ -28,20 +28,14 @@ describe "tgXhrErrorService", ->
provide.value "$q", mocks.q
_mockLocation = () ->
mocks.location = {
path: sinon.spy(),
replace: sinon.spy()
_mockErrorHandling = () ->
mocks.errorHandling = {
notfound: sinon.stub(),
permissionDenied: sinon.stub()
}
provide.value "$location", mocks.location
_mockNavUrls = () ->
mocks.navUrls = {
resolve: sinon.stub()
}
provide.value "$tgNavUrls", mocks.navUrls
provide.value "tgErrorHandlingService", mocks.errorHandling
_inject = (callback) ->
inject (_tgXhrErrorService_) ->
@ -52,8 +46,7 @@ describe "tgXhrErrorService", ->
module ($provide) ->
provide = $provide
_mockQ()
_mockLocation()
_mockNavUrls()
_mockErrorHandling()
return null
@ -70,23 +63,17 @@ describe "tgXhrErrorService", ->
status: 404
}
mocks.navUrls.resolve.withArgs("not-found").returns("not-found")
xhrErrorService.response(xhr)
expect(mocks.q.reject.withArgs(xhr)).to.be.calledOnce
expect(mocks.location.path.withArgs("not-found")).to.be.calledOnce
expect(mocks.location.replace).to.be.calledOnce
expect(mocks.errorHandling.notfound).to.be.calledOnce
it "403 status redirect to permission-denied page", () ->
xhr = {
status: 403
}
mocks.navUrls.resolve.withArgs("permission-denied").returns("permission-denied")
xhrErrorService.response(xhr)
expect(mocks.q.reject.withArgs(xhr)).to.be.calledOnce
expect(mocks.location.path.withArgs("permission-denied")).to.be.calledOnce
expect(mocks.location.replace).to.be.calledOnce
expect(mocks.errorHandling.permissionDenied).to.be.calledOnce