|
10 | 10 |
|
11 | 11 | abpModule.config([
|
12 | 12 | '$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 | + }); |
59 | 58 | }
|
60 | 59 | ]);
|
61 | 60 |
|
62 | 61 | abpModule.factory('services.tasksystem.task', [
|
63 |
| - 'abp.$http', function ($http) { |
| 62 | + '$http', function ($http) { |
64 | 63 | return new function () {
|
65 | 64 | //Working on this code!
|
66 | 65 | this.getTasks = function (input) {
|
67 | 66 | return $http({
|
68 | 67 | url: '/api/services/tasksystem/task/GetTasks',
|
69 | 68 | method: 'POST',
|
70 |
| - data: JSON.stringify(input) |
| 69 | + data: JSON.stringify(input), |
| 70 | + abp: true |
71 | 71 | });
|
72 | 72 | };
|
73 | 73 | };
|
|
0 commit comments