ismx-nexo-node-app 0.4.44 → 0.4.45
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.
|
@@ -41,17 +41,15 @@ class RepositoryRest extends Repository_1.default {
|
|
|
41
41
|
let call = fetch(this.baseUrl + endpoint + QueryUtils_1.default.map(request.query), Object.assign(Object.assign({}, request), { body: method !== "GET" ? JSON.stringify(request.body) : undefined, headers }));
|
|
42
42
|
// Añade información adicional a la respuesta y devuelve el resultado (o el error en su caso).
|
|
43
43
|
return call.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
var _a, _b, _c, _d;
|
|
44
|
+
var _a, _b, _c, _d, _e;
|
|
45
45
|
let headers = {};
|
|
46
46
|
res.headers.forEach((value, key) => headers[key] = value);
|
|
47
|
-
let
|
|
48
|
-
(_b = (_a = this.options).onRawResponse) === null || _b === void 0 ? void 0 : _b.call(_a, request,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
54
|
-
(_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.onResponse) === null || _d === void 0 ? void 0 : _d.call(_c, request, response);
|
|
47
|
+
let content = yield res.text();
|
|
48
|
+
(_b = (_a = this.options).onRawResponse) === null || _b === void 0 ? void 0 : _b.call(_a, request, content);
|
|
49
|
+
if ((_c = headers['Content-Type']) === null || _c === void 0 ? void 0 : _c.startsWith('application/json'))
|
|
50
|
+
content = JSON.parse(content, this.reviver);
|
|
51
|
+
let response = { httpCode: res.status, content: content, headers };
|
|
52
|
+
(_e = (_d = this.options) === null || _d === void 0 ? void 0 : _d.onResponse) === null || _e === void 0 ? void 0 : _e.call(_d, request, response);
|
|
55
53
|
return response;
|
|
56
54
|
})).catch((error) => {
|
|
57
55
|
var _a, _b;
|
package/package.json
CHANGED
|
@@ -56,15 +56,16 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
|
|
|
56
56
|
// Añade información adicional a la respuesta y devuelve el resultado (o el error en su caso).
|
|
57
57
|
return call.then(async (res: Response) => {
|
|
58
58
|
let headers: any = {}; res.headers.forEach((value, key) => headers[key] = value);
|
|
59
|
-
let
|
|
60
|
-
this.options.onRawResponse?.(request,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
content
|
|
64
|
-
|
|
65
|
-
};
|
|
59
|
+
let content: string | E = await res.text();
|
|
60
|
+
this.options.onRawResponse?.(request, content);
|
|
61
|
+
|
|
62
|
+
if (headers['Content-Type']?.startsWith('application/json'))
|
|
63
|
+
content = JSON.parse(content, this.reviver) as E;
|
|
64
|
+
|
|
65
|
+
let response: HttpResponse<E> = { httpCode: res.status, content: content as E, headers };
|
|
66
66
|
this.options?.onResponse?.(request, response);
|
|
67
67
|
return response;
|
|
68
|
+
|
|
68
69
|
}).catch((error) => {
|
|
69
70
|
this.options.onError?.(request, error);
|
|
70
71
|
throw error;
|