@esfaenza/httpservice 12.2.17 → 12.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/esfaenza-httpservice.umd.js +516 -62
- package/bundles/esfaenza-httpservice.umd.js.map +1 -1
- package/esfaenza-httpservice.metadata.json +1 -1
- package/esm2015/lib/httpservice.service.js +181 -60
- package/esm2015/lib/httpservice.service.loc.js +3 -2
- package/fesm2015/esfaenza-httpservice.js +182 -61
- package/fesm2015/esfaenza-httpservice.js.map +1 -1
- package/lib/httpservice.service.d.ts +61 -4
- package/lib/httpservice.service.loc.d.ts +4 -0
- package/package.json +3 -3
|
@@ -4,6 +4,315 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.esfaenza = global.esfaenza || {}, global.esfaenza.httpservice = {}), global.ng.common.http, global.ng.core, global.rxjs.operators, global.rxjs));
|
|
5
5
|
}(this, (function (exports, http, core, operators, rxjs) { 'use strict';
|
|
6
6
|
|
|
7
|
+
/*! *****************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
9
|
+
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
+
***************************************************************************** */
|
|
21
|
+
/* global Reflect, Promise */
|
|
22
|
+
var extendStatics = function (d, b) {
|
|
23
|
+
extendStatics = Object.setPrototypeOf ||
|
|
24
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
25
|
+
function (d, b) { for (var p in b)
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(b, p))
|
|
27
|
+
d[p] = b[p]; };
|
|
28
|
+
return extendStatics(d, b);
|
|
29
|
+
};
|
|
30
|
+
function __extends(d, b) {
|
|
31
|
+
if (typeof b !== "function" && b !== null)
|
|
32
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
33
|
+
extendStatics(d, b);
|
|
34
|
+
function __() { this.constructor = d; }
|
|
35
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
36
|
+
}
|
|
37
|
+
var __assign = function () {
|
|
38
|
+
__assign = Object.assign || function __assign(t) {
|
|
39
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
40
|
+
s = arguments[i];
|
|
41
|
+
for (var p in s)
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
43
|
+
t[p] = s[p];
|
|
44
|
+
}
|
|
45
|
+
return t;
|
|
46
|
+
};
|
|
47
|
+
return __assign.apply(this, arguments);
|
|
48
|
+
};
|
|
49
|
+
function __rest(s, e) {
|
|
50
|
+
var t = {};
|
|
51
|
+
for (var p in s)
|
|
52
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
53
|
+
t[p] = s[p];
|
|
54
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
55
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
56
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
57
|
+
t[p[i]] = s[p[i]];
|
|
58
|
+
}
|
|
59
|
+
return t;
|
|
60
|
+
}
|
|
61
|
+
function __decorate(decorators, target, key, desc) {
|
|
62
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
63
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
64
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
65
|
+
else
|
|
66
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
67
|
+
if (d = decorators[i])
|
|
68
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
69
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
70
|
+
}
|
|
71
|
+
function __param(paramIndex, decorator) {
|
|
72
|
+
return function (target, key) { decorator(target, key, paramIndex); };
|
|
73
|
+
}
|
|
74
|
+
function __metadata(metadataKey, metadataValue) {
|
|
75
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
76
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
77
|
+
}
|
|
78
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
79
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
80
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
81
|
+
function fulfilled(value) { try {
|
|
82
|
+
step(generator.next(value));
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
reject(e);
|
|
86
|
+
} }
|
|
87
|
+
function rejected(value) { try {
|
|
88
|
+
step(generator["throw"](value));
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
reject(e);
|
|
92
|
+
} }
|
|
93
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
94
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function __generator(thisArg, body) {
|
|
98
|
+
var _ = { label: 0, sent: function () { if (t[0] & 1)
|
|
99
|
+
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
100
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
|
101
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
102
|
+
function step(op) {
|
|
103
|
+
if (f)
|
|
104
|
+
throw new TypeError("Generator is already executing.");
|
|
105
|
+
while (_)
|
|
106
|
+
try {
|
|
107
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
108
|
+
return t;
|
|
109
|
+
if (y = 0, t)
|
|
110
|
+
op = [op[0] & 2, t.value];
|
|
111
|
+
switch (op[0]) {
|
|
112
|
+
case 0:
|
|
113
|
+
case 1:
|
|
114
|
+
t = op;
|
|
115
|
+
break;
|
|
116
|
+
case 4:
|
|
117
|
+
_.label++;
|
|
118
|
+
return { value: op[1], done: false };
|
|
119
|
+
case 5:
|
|
120
|
+
_.label++;
|
|
121
|
+
y = op[1];
|
|
122
|
+
op = [0];
|
|
123
|
+
continue;
|
|
124
|
+
case 7:
|
|
125
|
+
op = _.ops.pop();
|
|
126
|
+
_.trys.pop();
|
|
127
|
+
continue;
|
|
128
|
+
default:
|
|
129
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
130
|
+
_ = 0;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
134
|
+
_.label = op[1];
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
138
|
+
_.label = t[1];
|
|
139
|
+
t = op;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
if (t && _.label < t[2]) {
|
|
143
|
+
_.label = t[2];
|
|
144
|
+
_.ops.push(op);
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
if (t[2])
|
|
148
|
+
_.ops.pop();
|
|
149
|
+
_.trys.pop();
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
op = body.call(thisArg, _);
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
op = [6, e];
|
|
156
|
+
y = 0;
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
f = t = 0;
|
|
160
|
+
}
|
|
161
|
+
if (op[0] & 5)
|
|
162
|
+
throw op[1];
|
|
163
|
+
return { value: op[0] ? op[1] : void 0, done: true };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
var __createBinding = Object.create ? (function (o, m, k, k2) {
|
|
167
|
+
if (k2 === undefined)
|
|
168
|
+
k2 = k;
|
|
169
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
|
170
|
+
}) : (function (o, m, k, k2) {
|
|
171
|
+
if (k2 === undefined)
|
|
172
|
+
k2 = k;
|
|
173
|
+
o[k2] = m[k];
|
|
174
|
+
});
|
|
175
|
+
function __exportStar(m, o) {
|
|
176
|
+
for (var p in m)
|
|
177
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
|
178
|
+
__createBinding(o, m, p);
|
|
179
|
+
}
|
|
180
|
+
function __values(o) {
|
|
181
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
182
|
+
if (m)
|
|
183
|
+
return m.call(o);
|
|
184
|
+
if (o && typeof o.length === "number")
|
|
185
|
+
return {
|
|
186
|
+
next: function () {
|
|
187
|
+
if (o && i >= o.length)
|
|
188
|
+
o = void 0;
|
|
189
|
+
return { value: o && o[i++], done: !o };
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
193
|
+
}
|
|
194
|
+
function __read(o, n) {
|
|
195
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
196
|
+
if (!m)
|
|
197
|
+
return o;
|
|
198
|
+
var i = m.call(o), r, ar = [], e;
|
|
199
|
+
try {
|
|
200
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
|
201
|
+
ar.push(r.value);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
e = { error: error };
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
try {
|
|
208
|
+
if (r && !r.done && (m = i["return"]))
|
|
209
|
+
m.call(i);
|
|
210
|
+
}
|
|
211
|
+
finally {
|
|
212
|
+
if (e)
|
|
213
|
+
throw e.error;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return ar;
|
|
217
|
+
}
|
|
218
|
+
/** @deprecated */
|
|
219
|
+
function __spread() {
|
|
220
|
+
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
221
|
+
ar = ar.concat(__read(arguments[i]));
|
|
222
|
+
return ar;
|
|
223
|
+
}
|
|
224
|
+
/** @deprecated */
|
|
225
|
+
function __spreadArrays() {
|
|
226
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
|
227
|
+
s += arguments[i].length;
|
|
228
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
229
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
230
|
+
r[k] = a[j];
|
|
231
|
+
return r;
|
|
232
|
+
}
|
|
233
|
+
function __spreadArray(to, from) {
|
|
234
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
235
|
+
to[j] = from[i];
|
|
236
|
+
return to;
|
|
237
|
+
}
|
|
238
|
+
function __await(v) {
|
|
239
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
240
|
+
}
|
|
241
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
242
|
+
if (!Symbol.asyncIterator)
|
|
243
|
+
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
244
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
245
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
246
|
+
function verb(n) { if (g[n])
|
|
247
|
+
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
248
|
+
function resume(n, v) { try {
|
|
249
|
+
step(g[n](v));
|
|
250
|
+
}
|
|
251
|
+
catch (e) {
|
|
252
|
+
settle(q[0][3], e);
|
|
253
|
+
} }
|
|
254
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
255
|
+
function fulfill(value) { resume("next", value); }
|
|
256
|
+
function reject(value) { resume("throw", value); }
|
|
257
|
+
function settle(f, v) { if (f(v), q.shift(), q.length)
|
|
258
|
+
resume(q[0][0], q[0][1]); }
|
|
259
|
+
}
|
|
260
|
+
function __asyncDelegator(o) {
|
|
261
|
+
var i, p;
|
|
262
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
263
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
|
264
|
+
}
|
|
265
|
+
function __asyncValues(o) {
|
|
266
|
+
if (!Symbol.asyncIterator)
|
|
267
|
+
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
268
|
+
var m = o[Symbol.asyncIterator], i;
|
|
269
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
270
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
271
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
|
272
|
+
}
|
|
273
|
+
function __makeTemplateObject(cooked, raw) {
|
|
274
|
+
if (Object.defineProperty) {
|
|
275
|
+
Object.defineProperty(cooked, "raw", { value: raw });
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
cooked.raw = raw;
|
|
279
|
+
}
|
|
280
|
+
return cooked;
|
|
281
|
+
}
|
|
282
|
+
;
|
|
283
|
+
var __setModuleDefault = Object.create ? (function (o, v) {
|
|
284
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
285
|
+
}) : function (o, v) {
|
|
286
|
+
o["default"] = v;
|
|
287
|
+
};
|
|
288
|
+
function __importStar(mod) {
|
|
289
|
+
if (mod && mod.__esModule)
|
|
290
|
+
return mod;
|
|
291
|
+
var result = {};
|
|
292
|
+
if (mod != null)
|
|
293
|
+
for (var k in mod)
|
|
294
|
+
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
295
|
+
__createBinding(result, mod, k);
|
|
296
|
+
__setModuleDefault(result, mod);
|
|
297
|
+
return result;
|
|
298
|
+
}
|
|
299
|
+
function __importDefault(mod) {
|
|
300
|
+
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
301
|
+
}
|
|
302
|
+
function __classPrivateFieldGet(receiver, privateMap) {
|
|
303
|
+
if (!privateMap.has(receiver)) {
|
|
304
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
305
|
+
}
|
|
306
|
+
return privateMap.get(receiver);
|
|
307
|
+
}
|
|
308
|
+
function __classPrivateFieldSet(receiver, privateMap, value) {
|
|
309
|
+
if (!privateMap.has(receiver)) {
|
|
310
|
+
throw new TypeError("attempted to set private field on non-instance");
|
|
311
|
+
}
|
|
312
|
+
privateMap.set(receiver, value);
|
|
313
|
+
return value;
|
|
314
|
+
}
|
|
315
|
+
|
|
7
316
|
/**
|
|
8
317
|
* Dizionario di invalidazioni delle chiamate HTTP
|
|
9
318
|
*/
|
|
@@ -134,10 +443,10 @@
|
|
|
134
443
|
"redirecting to login": { "en-US": "redirecting to login", "it-IT": "redireziono al login", },
|
|
135
444
|
"Redirecting to Login, ignoring HTTP error on call": { "en-US": "Redirecting to Login, ignoring HTTP error on call", "it-IT": "Redireziono al login ignorando errori sulla chiamata", },
|
|
136
445
|
"Already Handling an error, ignoring HTTP error on call": { "en-US": "Already Handling an error, ignoring HTTP error on call", "it-IT": "sto già gestendo un errore, ignoro quello corrente per la chiamata HTTP", },
|
|
137
|
-
"Error 444 on call": { "en-US": "Error 444 on call", "it-IT": "Errore 444 su chiamata"
|
|
446
|
+
"Error 444 on call": { "en-US": "Error 444 on call", "it-IT": "Errore 444 su chiamata" },
|
|
447
|
+
"Resource not found": { "en-US": "Resource not found", "it-IT": "Risorsa non trovata" }
|
|
138
448
|
};
|
|
139
449
|
|
|
140
|
-
// Angular
|
|
141
450
|
/**
|
|
142
451
|
* Servizio utilizzato per effettuare qualsiasi tipo di chiamata HTTP dall'applicazione, gestisce errori e cache delle risposte nativamente e ne può essere
|
|
143
452
|
* esteso/modificato il comportamento implementando la classe di "hook" **IHttpServiceExtensions** e registrandola nel provider della classe **HttpServiceExtensions**
|
|
@@ -265,23 +574,75 @@
|
|
|
265
574
|
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
266
575
|
};
|
|
267
576
|
/**
|
|
268
|
-
* Esecuzione di una POST HTTP
|
|
269
|
-
*
|
|
577
|
+
* Esecuzione di una POST HTTP
|
|
270
578
|
*
|
|
271
579
|
* @param {string} url URL su cui effettuare la chiamata
|
|
272
580
|
* @param {any} bodyData DTO per la chiamata
|
|
581
|
+
* @param {HttpParams} params Parametri della chiamata
|
|
582
|
+
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
583
|
+
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
584
|
+
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
585
|
+
*
|
|
586
|
+
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
587
|
+
*/
|
|
588
|
+
HTTPService.prototype.post = function (url, bodyData, params, transaction, succesfulResultMandatory) {
|
|
589
|
+
var _this = this;
|
|
590
|
+
if (params === void 0) { params = null; }
|
|
591
|
+
if (transaction === void 0) { transaction = ""; }
|
|
592
|
+
if (succesfulResultMandatory === void 0) { succesfulResultMandatory = true; }
|
|
593
|
+
var myGuid = this.defaultStartCall(url);
|
|
594
|
+
var httpCall = this.http.post(url, bodyData, { headers: this.getHeaders(transaction), params: params });
|
|
595
|
+
return httpCall.pipe(operators.map(function (res) {
|
|
596
|
+
var responseItem = res;
|
|
597
|
+
return responseItem;
|
|
598
|
+
}), operators.catchError(function (err, caught) {
|
|
599
|
+
return !succesfulResultMandatory ? rxjs.throwError(err) : _this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
600
|
+
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
601
|
+
};
|
|
602
|
+
/**
|
|
603
|
+
* Esecuzione di una DELETE HTTP
|
|
604
|
+
*
|
|
605
|
+
* @param {string} url URL su cui effettuare la chiamata
|
|
606
|
+
* @param {HttpParams} params Parametri della chiamata
|
|
273
607
|
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
274
608
|
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
275
609
|
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
276
610
|
*
|
|
277
611
|
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
278
612
|
*/
|
|
279
|
-
HTTPService.prototype.
|
|
613
|
+
HTTPService.prototype.delete = function (url, params, transaction, succesfulResultMandatory) {
|
|
614
|
+
var _this = this;
|
|
615
|
+
if (params === void 0) { params = null; }
|
|
616
|
+
if (transaction === void 0) { transaction = ""; }
|
|
617
|
+
if (succesfulResultMandatory === void 0) { succesfulResultMandatory = true; }
|
|
618
|
+
var myGuid = this.defaultStartCall(url);
|
|
619
|
+
var httpCall = this.http.delete(url, { headers: this.getHeaders(transaction), params: params });
|
|
620
|
+
return httpCall.pipe(operators.map(function (res) {
|
|
621
|
+
var responseItem = res;
|
|
622
|
+
return responseItem;
|
|
623
|
+
}), operators.catchError(function (err, caught) {
|
|
624
|
+
return !succesfulResultMandatory ? rxjs.throwError(err) : _this.registerErrorAndReturnEmptyObservable(err, myGuid);
|
|
625
|
+
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); }));
|
|
626
|
+
};
|
|
627
|
+
/**
|
|
628
|
+
* Esecuzione di una PUT HTTP
|
|
629
|
+
*
|
|
630
|
+
* @param {string} url URL su cui effettuare la chiamata
|
|
631
|
+
* @param {any} bodyData DTO per la chiamata
|
|
632
|
+
* @param {HttpParams} params Parametri della chiamata
|
|
633
|
+
* @param {string} transaction Codice transazione collegato a questa chiamata. Viene inserito nell'Header "X-TX-ID" e lato Backend dovrà essere gestito di conseguenza
|
|
634
|
+
* @param {boolean} succesfulResultMandatory Indica che questa chiamata deve assolutamente andare bene. In caso contrario viene fisicamente fatto il throw che può essere
|
|
635
|
+
* raccolto da chi usa la libreria nella pipe "onError" dell'Observable restituito ed essere gestito in maniera non standard
|
|
636
|
+
*
|
|
637
|
+
* @returns {Observable<T>} Observable che contiene il risultato della chiamata
|
|
638
|
+
*/
|
|
639
|
+
HTTPService.prototype.put = function (url, bodyData, params, transaction, succesfulResultMandatory) {
|
|
280
640
|
var _this = this;
|
|
641
|
+
if (params === void 0) { params = null; }
|
|
281
642
|
if (transaction === void 0) { transaction = ""; }
|
|
282
643
|
if (succesfulResultMandatory === void 0) { succesfulResultMandatory = true; }
|
|
283
644
|
var myGuid = this.defaultStartCall(url);
|
|
284
|
-
var httpCall = this.http.
|
|
645
|
+
var httpCall = this.http.put(url, bodyData, { headers: this.getHeaders(transaction), params: params });
|
|
285
646
|
return httpCall.pipe(operators.map(function (res) {
|
|
286
647
|
var responseItem = res;
|
|
287
648
|
return responseItem;
|
|
@@ -316,7 +677,7 @@
|
|
|
316
677
|
*
|
|
317
678
|
* @param {string} url URL su cui effettuare la chiamata
|
|
318
679
|
* @param {K} bodyData DTO per la chiamata
|
|
319
|
-
* @param {string} filename Nome del file che si sta richiedendo, rimane lato Frontend e serve per assegnare arbitrariamente un nome al file restituito
|
|
680
|
+
* @param {string} filename Nome del file che si sta richiedendo, rimane lato Frontend e serve per assegnare arbitrariamente un nome al file restituito, se vuoto viene utilizzata la Content-Disposition della risposta
|
|
320
681
|
* @param {Function} getFileCallback Callback a due parametri (url: string, filename: string) per gestire il risultato del file richiesto. **Utilizzare UtilityService.fileDownload** di @esfaenza/extensions
|
|
321
682
|
* @param {Function} afterGetFile Callback da chiamare dopo aver gestito la risposta del **getFileCallback**, in caso **handleError** fosse **false** verrà richiamato anche in caso di errore
|
|
322
683
|
* @param {boolean} handleError Indica se di default gli errori devono essere gestiti dalla libreria o se devono essere ignorati
|
|
@@ -331,12 +692,42 @@
|
|
|
331
692
|
afterGetFile();
|
|
332
693
|
return _this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
|
|
333
694
|
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); })).subscribe(function (response) {
|
|
334
|
-
var
|
|
335
|
-
var retUrl = window.URL.createObjectURL(
|
|
336
|
-
var
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
695
|
+
var _a, _b, _c, _d;
|
|
696
|
+
var retUrl = window.URL.createObjectURL(response.body);
|
|
697
|
+
var fn = (_d = (_c = (_b = (_a = response.headers.get('content-disposition')) === null || _a === void 0 ? void 0 : _a.split(';')[1]) === null || _b === void 0 ? void 0 : _b.split('filename')[1]) === null || _c === void 0 ? void 0 : _c.split('=')[1]) === null || _d === void 0 ? void 0 : _d.trim().replace(/\"/g, '');
|
|
698
|
+
getFileCallback(retUrl, filename || fn);
|
|
699
|
+
if (afterGetFile)
|
|
700
|
+
afterGetFile();
|
|
701
|
+
});
|
|
702
|
+
};
|
|
703
|
+
/**
|
|
704
|
+
* Esecuzione di una GET HTTP
|
|
705
|
+
*
|
|
706
|
+
* Casistica particolare in cui viene restituito un file gestito come ObjectURL il cui URL si può gestire dal parametro di callback **getFileCallback**.
|
|
707
|
+
* La chiamata non ha un tipo restituito in quanto il risultato dev'essere gestito attraverso la callback **getFileCallback**
|
|
708
|
+
*
|
|
709
|
+
* @param {string} url URL su cui effettuare la chiamata
|
|
710
|
+
* @param {HttpParams} params Parametri della chiamata
|
|
711
|
+
* @param {string} filename Nome del file che si sta richiedendo, rimane lato Frontend e serve per assegnare arbitrariamente un nome al file restituito, se vuoto viene utilizzata la Content-Disposition della risposta
|
|
712
|
+
* @param {Function} getFileCallback Callback a due parametri (url: string, filename: string) per gestire il risultato del file richiesto. **Utilizzare UtilityService.fileDownload** di @esfaenza/extensions
|
|
713
|
+
* @param {Function} afterGetFile Callback da chiamare dopo aver gestito la risposta del **getFileCallback**, in caso **handleError** fosse **false** verrà richiamato anche in caso di errore
|
|
714
|
+
* @param {boolean} handleError Indica se di default gli errori devono essere gestiti dalla libreria o se devono essere ignorati
|
|
715
|
+
*/
|
|
716
|
+
HTTPService.prototype.getFile = function (url, params, filename, getFileCallback, afterGetFile, handleError) {
|
|
717
|
+
var _this = this;
|
|
718
|
+
if (params === void 0) { params = null; }
|
|
719
|
+
if (afterGetFile === void 0) { afterGetFile = null; }
|
|
720
|
+
if (handleError === void 0) { handleError = true; }
|
|
721
|
+
var myGuid = this.defaultStartCall(url);
|
|
722
|
+
this.http.get(url, { params: params, headers: this.getHeaders(), observe: 'response', responseType: "blob" }).pipe(operators.catchError(function (err, caught) {
|
|
723
|
+
if (afterGetFile && !handleError)
|
|
724
|
+
afterGetFile();
|
|
725
|
+
return _this.registerErrorAndReturnEmptyObservable(err, myGuid, handleError);
|
|
726
|
+
}), operators.finalize(function () { _this.tryFinalizeByGuid(myGuid); })).subscribe(function (response) {
|
|
727
|
+
var _a, _b, _c, _d;
|
|
728
|
+
var retUrl = window.URL.createObjectURL(response.body);
|
|
729
|
+
var fn = (_d = (_c = (_b = (_a = response.headers.get('content-disposition')) === null || _a === void 0 ? void 0 : _a.split(';')[1]) === null || _b === void 0 ? void 0 : _b.split('filename')[1]) === null || _c === void 0 ? void 0 : _c.split('=')[1]) === null || _d === void 0 ? void 0 : _d.trim().replace(/\"/g, '');
|
|
730
|
+
getFileCallback(retUrl, filename || fn);
|
|
340
731
|
if (afterGetFile)
|
|
341
732
|
afterGetFile();
|
|
342
733
|
});
|
|
@@ -349,7 +740,7 @@
|
|
|
349
740
|
*/
|
|
350
741
|
HTTPService.prototype.getFileNative = function (url, params) {
|
|
351
742
|
if (params === void 0) { params = null; }
|
|
352
|
-
var finalUrl = url + "?" + params.toString();
|
|
743
|
+
var finalUrl = url + (params ? "?" + params.toString() : "");
|
|
353
744
|
window.location.href = finalUrl;
|
|
354
745
|
};
|
|
355
746
|
/**
|
|
@@ -511,65 +902,128 @@
|
|
|
511
902
|
* @param {string} guid Identificativo GUID della chiamata effettuata
|
|
512
903
|
*/
|
|
513
904
|
HTTPService.prototype.onError = function (res, guid) {
|
|
514
|
-
this
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
905
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
906
|
+
var finalError, finalStatus;
|
|
907
|
+
return __generator(this, function (_e) {
|
|
908
|
+
switch (_e.label) {
|
|
909
|
+
case 0:
|
|
910
|
+
this.callStatus[guid] = false;
|
|
911
|
+
//Mi assicuro che tutti gli errori durante il redirect al login vengano ignorati
|
|
912
|
+
if (this.ExtensionsImpl.readRedirectingToLogin()) {
|
|
913
|
+
this.log(this.loc("Redirecting to Login, ignoring HTTP error on call") + " " + guid);
|
|
914
|
+
return [2 /*return*/];
|
|
915
|
+
}
|
|
916
|
+
//Mi assicuro che venga gestito un solo errore per volta
|
|
917
|
+
if (this.ExtensionsImpl.readHandlingErrorStatus()) {
|
|
918
|
+
this.log(this.loc("Already Handling an error, ignoring HTTP error on call") + " " + guid);
|
|
919
|
+
return [2 /*return*/];
|
|
920
|
+
}
|
|
921
|
+
else
|
|
922
|
+
this.ExtensionsImpl.writeHandlingErrorStatus(true);
|
|
923
|
+
finalError = "";
|
|
924
|
+
finalStatus = "";
|
|
925
|
+
if (!this.isTypeError(res)) return [3 /*break*/, 1];
|
|
926
|
+
finalError = res.message;
|
|
927
|
+
finalStatus = "HTTP Service Internal Error";
|
|
928
|
+
return [3 /*break*/, 3];
|
|
929
|
+
case 1:
|
|
930
|
+
if (!this.isHttpErrorResponse(res)) return [3 /*break*/, 3];
|
|
931
|
+
return [4 /*yield*/, this.getHttpErrorText(res.error)];
|
|
932
|
+
case 2:
|
|
933
|
+
finalError = _e.sent();
|
|
934
|
+
finalStatus = res.status.toString();
|
|
935
|
+
switch (res.status) {
|
|
936
|
+
// Unauthorized
|
|
937
|
+
case 401:
|
|
938
|
+
if (this.ExtensionsImpl.readRedirectionStatus()) {
|
|
939
|
+
this.log(this.loc("Error 401 on call") + " " + guid + " " + this.loc("with redirect already in progress. Ignoring this event"));
|
|
940
|
+
return [2 /*return*/];
|
|
941
|
+
}
|
|
942
|
+
this.log(this.loc("Error 401 on call") + " " + guid + " " + this.loc("redirecting to login."));
|
|
943
|
+
this.ExtensionsImpl.writeRedirectionStatus(true);
|
|
944
|
+
this.ExtensionsImpl.writeRedirectingToLogin(true);
|
|
945
|
+
this.ExtensionsImpl.redirectToLogin();
|
|
946
|
+
return [2 /*return*/];
|
|
947
|
+
// Handled exception
|
|
948
|
+
case 400:
|
|
949
|
+
// No Permissions
|
|
950
|
+
case 403:
|
|
951
|
+
this.ExtensionsImpl.handleBlockingException(res.status, finalError);
|
|
952
|
+
return [2 /*return*/];
|
|
953
|
+
// Not found
|
|
954
|
+
case 404:
|
|
955
|
+
this.ExtensionsImpl.handleBlockingException(res.status, this.loc("Resource not found"));
|
|
956
|
+
return [2 /*return*/];
|
|
957
|
+
// NotConfiguredException
|
|
958
|
+
case 444:
|
|
959
|
+
if (this.ExtensionsImpl.readRedirectionStatus())
|
|
960
|
+
this.log(this.loc("Error 444 on call") + " " + guid + " " + this.loc("with redirect already in progress. Ignoring this event"));
|
|
961
|
+
else if (!this.ExtensionsImpl.handleNotConfiguredException())
|
|
962
|
+
this.ExtensionsImpl.handleBlockingException(res.status, finalError);
|
|
963
|
+
return [2 /*return*/];
|
|
964
|
+
case 0:
|
|
965
|
+
finalError = "Server might be offline" + (res.statusText ? " (" + res.statusText + ") " : "");
|
|
966
|
+
}
|
|
967
|
+
_e.label = 3;
|
|
968
|
+
case 3:
|
|
969
|
+
this.ExtensionsImpl.handleException(finalStatus, finalError);
|
|
970
|
+
return [2 /*return*/];
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
});
|
|
974
|
+
};
|
|
975
|
+
/**
|
|
976
|
+
* Dato un errore restituisce una promise con la stringa finale dell'errore in modo da poter fare un await
|
|
977
|
+
*
|
|
978
|
+
* @param {any} err Errore da controllare
|
|
979
|
+
*
|
|
980
|
+
* @returns {Promise<string>} Promise che risolve con la stringa finale dell'errore
|
|
981
|
+
*/
|
|
982
|
+
HTTPService.prototype.getHttpErrorText = function (err) {
|
|
983
|
+
var _this = this;
|
|
984
|
+
// Se ho un Blob può essere o un CallResult o suppongo una semplice stringa,
|
|
985
|
+
// altrimenti potrebbe essere direttamente un CallResult, oppure una semplice stringa
|
|
986
|
+
return new Promise(function (resolve) {
|
|
987
|
+
if (err instanceof Blob) {
|
|
988
|
+
var reader = new FileReader();
|
|
989
|
+
reader.onload = function (e) {
|
|
990
|
+
var errMsg = e.target.result;
|
|
991
|
+
var jsonerrMsg;
|
|
992
|
+
try {
|
|
993
|
+
jsonerrMsg = JSON.parse(errMsg);
|
|
542
994
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
return;
|
|
548
|
-
// NotConfiguredException
|
|
549
|
-
case 444:
|
|
550
|
-
if (this.ExtensionsImpl.readRedirectionStatus())
|
|
551
|
-
this.log(this.loc("Error 444 on call") + " " + guid + " " + this.loc("with redirect already in progress. Ignoring this event"));
|
|
552
|
-
else if (!this.ExtensionsImpl.handleNotConfiguredException())
|
|
553
|
-
this.ExtensionsImpl.handleBlockingException(res.status, finalError);
|
|
554
|
-
return;
|
|
555
|
-
// No Permissions
|
|
556
|
-
case 403:
|
|
557
|
-
this.ExtensionsImpl.handleBlockingException(res.status, finalError);
|
|
558
|
-
return;
|
|
559
|
-
case 0:
|
|
560
|
-
finalError = "Server Offline?" + res.statusText ? " (" + res.statusText + ") " : "";
|
|
995
|
+
catch (e) { }
|
|
996
|
+
return resolve(jsonerrMsg && _this.isCallResult(jsonerrMsg) ? jsonerrMsg.error.message : errMsg);
|
|
997
|
+
};
|
|
998
|
+
reader.readAsText(err);
|
|
561
999
|
}
|
|
562
|
-
|
|
563
|
-
|
|
1000
|
+
else if (_this.isCallResult(err))
|
|
1001
|
+
return resolve(err.error.message);
|
|
1002
|
+
else
|
|
1003
|
+
return resolve(err === null || err === void 0 ? void 0 : err.toString());
|
|
1004
|
+
});
|
|
1005
|
+
};
|
|
1006
|
+
/**
|
|
1007
|
+
* Riconosce se l'oggetto è di tipo **CallResult** e, se sì, lo casta al tipo corretto per essere utilizzato correttamente nel blocco di codice successivo
|
|
1008
|
+
*
|
|
1009
|
+
* @param {any} err Errore da controllare
|
|
1010
|
+
*/
|
|
1011
|
+
HTTPService.prototype.isCallResult = function (err) {
|
|
1012
|
+
var _a;
|
|
1013
|
+
return !!((_a = err === null || err === void 0 ? void 0 : err.error) === null || _a === void 0 ? void 0 : _a.message);
|
|
564
1014
|
};
|
|
565
1015
|
/**
|
|
566
1016
|
* Riconosce se l'errore è di tipo **HttpErrorResponse** e, se sì, lo casta al tipo corretto per essere utilizzato correttamente nel blocco di codice successivo
|
|
1017
|
+
*
|
|
1018
|
+
* @param {any} err Errore da controllare
|
|
567
1019
|
*/
|
|
568
1020
|
HTTPService.prototype.isHttpErrorResponse = function (err) {
|
|
569
1021
|
return err instanceof http.HttpErrorResponse;
|
|
570
1022
|
};
|
|
571
1023
|
/**
|
|
572
1024
|
* Riconosce se l'errore è di tipo **TypeError** e, se sì, lo casta al tipo corretto per essere utilizzato correttamente nel blocco di codice successivo
|
|
1025
|
+
*
|
|
1026
|
+
* @param {any} err Errore da controllare
|
|
573
1027
|
*/
|
|
574
1028
|
HTTPService.prototype.isTypeError = function (err) {
|
|
575
1029
|
return err.name == "TypeError";
|