|
10 | 10 |
|
11 | 11 | abpModule.config([
|
12 | 12 | '$httpProvider', function ($httpProvider) {
|
13 |
| - $httpProvider.interceptors.push(function () { |
| 13 | + $httpProvider.interceptors.push(function ($q) { |
14 | 14 | return {
|
15 |
| - 'request': function (config) { |
16 |
| - return config; |
17 |
| - }, |
18 |
| - |
19 | 15 | 'response': function (response) {
|
20 |
| - if (!response.config || !response.config.abp) { |
| 16 | + if (!response.config || !response.config.abp || !response.data) { |
21 | 17 | return response;
|
22 | 18 | }
|
23 | 19 |
|
24 |
| - //var data = response.data; |
25 |
| - if (!response.data) { //Needless check? |
26 |
| - return response; |
27 |
| - } |
| 20 | + var defer = $q.defer(); |
28 | 21 |
|
29 | 22 | if (response.data.targetUrl) { //TODO: Check if it works and does not prevent return value!
|
30 | 23 | location.href = data.targetUrl;
|
31 | 24 | }
|
32 | 25 |
|
33 | 26 | if (response.data.success === true) {
|
34 | 27 | response.data = response.data.result;
|
| 28 | + defer.resolve(response); |
35 | 29 | } else { //data.success === false
|
36 | 30 | if (response.data.error) {
|
37 |
| - //abp.log.error(response.data.error.details); |
38 | 31 | abp.message.error(response.data.error.message);
|
39 |
| - throw response.data.error.message; |
| 32 | + } else { |
| 33 | + response.data.error = { |
| 34 | + message: 'Ajax request is not succeed!', |
| 35 | + details: 'Error detail is not sent by server.' |
| 36 | + }; |
40 | 37 | }
|
41 | 38 |
|
| 39 | + abp.log.error(response.data.error.message + ' | ' + response.data.error.details); |
| 40 | + |
| 41 | + response.data = response.data.error; |
| 42 | + defer.reject(response); |
| 43 | + |
42 | 44 | if (response.data.unAuthorizedRequest && !response.data.targetUrl) {
|
43 | 45 | location.reload();
|
44 | 46 | }
|
45 | 47 | }
|
46 | 48 |
|
47 |
| - return response; |
48 |
| - }, |
49 |
| - |
50 |
| - //'responseError': function (rejection) { |
51 |
| - // alert(1); |
52 |
| - // console.log('asd: ' + rejection); |
53 |
| - |
54 |
| - // return $q.reject(rejection); |
55 |
| - //} |
| 49 | + return defer.promise; |
| 50 | + } |
56 | 51 | };
|
57 | 52 | });
|
58 | 53 | }
|
|
61 | 56 | abpModule.factory('services.tasksystem.task', [
|
62 | 57 | '$http', function ($http) {
|
63 | 58 | return new function () {
|
64 |
| - //Working on this code! |
65 | 59 | this.getTasks = function (input) {
|
66 | 60 | return $http({
|
67 | 61 | url: '/api/services/tasksystem/task/GetTasks',
|
|
0 commit comments