0
我有我的應用程序使用passport
工作的認證方。 這會給我一個403
當用戶不能訪問特定的路由,這也包括API路由。React在ajax調用重新路由
即
app.use('/api/calendar', passport, authorize([roles.SOME_ROLE]), calendar);
後來我把這個api/calendar
路線到達一個日曆,像這樣:
var getAll = function() {
return $.get(routes.MAIN + routes.GET_CALENDAR)
.error(function(error) {
//this is where I am stuck
});
}
如何,當我到了錯誤部分,重定向到另一個路線?
請注意,這個文件是一個服務文件,該getAll
方法從React
組件調用:
loadCalendar: function() {
var self = this;
calendarService.getAll()
.then(function (data) {
self.props.load(data);
});
},
我知道我能做到這一點在這個loadCalendar
功能,但是這將意味着,任何時候我做了打電話給我需要包括一個error
塊的任何服務,我寧願將它集中在service
文件中。