Skip to content

Commit ca1acbd

Browse files
committed
Worked on $http interceptors
1 parent bcb4db7 commit ca1acbd

File tree

1 file changed

+48
-48
lines changed
  • SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.Web/Abp/Framework/scripts/libs/angular

1 file changed

+48
-48
lines changed

SimpleTaskSystemSPA_AngularJs_EntityFramework/SimpleTaskSystem.Web/Abp/Framework/scripts/libs/angular/abp.ng.js

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,64 +10,64 @@
1010

1111
abpModule.config([
1212
'$httpProvider', function ($httpProvider) {
13-
//$httpProvider.defaults.transformResponse.push(function (a) {
14-
// return a;
15-
//});
16-
}
17-
]);
18-
19-
abpModule.factory('abp.$http', [
20-
'$q', '$http', function ($q, $http) {
21-
22-
//var defaultOptions = {
23-
// transformResponse: function (strData) {
24-
// if (!strData) {
25-
// return strData;
26-
// }
27-
28-
// var data = JSON.parse(strData);
29-
// if (!data) { //Needless check?
30-
// return strData;
31-
// }
32-
33-
// if (data.targetUrl) { //TODO: Check if it works and does not prevent return value!
34-
// location.href = data.targetUrl;
35-
// }
36-
37-
// if (data.success === true) {
38-
// return data.result;
39-
// } else { //data.success === false
40-
// if (data.error) {
41-
// abp.log.error(data.error.details);
42-
// abp.message.error(data.error.message);
43-
// }
44-
45-
// if (data.unAuthorizedRequest && !data.targetUrl) {
46-
// location.reload();
47-
// }
48-
49-
// return data;
50-
// }
51-
52-
// }
53-
//};
54-
55-
return function (options) {
56-
57-
return $http($.extend({}, defaultOptions, options));
58-
};
13+
$httpProvider.interceptors.push(function () {
14+
return {
15+
'request': function (config) {
16+
return config;
17+
},
18+
19+
'response': function (response) {
20+
if (!response.config || !response.config.abp) {
21+
return response;
22+
}
23+
24+
//var data = response.data;
25+
if (!response.data) { //Needless check?
26+
return response;
27+
}
28+
29+
if (response.data.targetUrl) { //TODO: Check if it works and does not prevent return value!
30+
location.href = data.targetUrl;
31+
}
32+
33+
if (response.data.success === true) {
34+
response.data = response.data.result;
35+
} else { //data.success === false
36+
if (response.data.error) {
37+
//abp.log.error(response.data.error.details);
38+
abp.message.error(response.data.error.message);
39+
throw response.data.error.message;
40+
}
41+
42+
if (response.data.unAuthorizedRequest && !response.data.targetUrl) {
43+
location.reload();
44+
}
45+
}
46+
47+
return response;
48+
},
49+
50+
//'responseError': function (rejection) {
51+
// alert(1);
52+
// console.log('asd: ' + rejection);
53+
54+
// return $q.reject(rejection);
55+
//}
56+
};
57+
});
5958
}
6059
]);
6160

6261
abpModule.factory('services.tasksystem.task', [
63-
'abp.$http', function ($http) {
62+
'$http', function ($http) {
6463
return new function () {
6564
//Working on this code!
6665
this.getTasks = function (input) {
6766
return $http({
6867
url: '/api/services/tasksystem/task/GetTasks',
6968
method: 'POST',
70-
data: JSON.stringify(input)
69+
data: JSON.stringify(input),
70+
abp: true
7171
});
7272
};
7373
};

0 commit comments

Comments
 (0)