ismx-nexo-node-app 0.4.24 → 0.4.25
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.
|
@@ -42,17 +42,17 @@ class RepositoryRest extends Repository_1.default {
|
|
|
42
42
|
let headers = {};
|
|
43
43
|
res.headers.forEach((value, key) => headers[key] = value);
|
|
44
44
|
let rawResponse = yield res.text();
|
|
45
|
-
(_b = (_a = this.options).onRawResponse) === null || _b === void 0 ? void 0 : _b.call(_a, rawResponse);
|
|
45
|
+
(_b = (_a = this.options).onRawResponse) === null || _b === void 0 ? void 0 : _b.call(_a, request, rawResponse);
|
|
46
46
|
let response = {
|
|
47
47
|
httpCode: res.status,
|
|
48
|
-
content: JSON.
|
|
48
|
+
content: JSON.parse(rawResponse),
|
|
49
49
|
headers
|
|
50
50
|
};
|
|
51
|
-
(_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.onResponse) === null || _d === void 0 ? void 0 : _d.call(_c, response);
|
|
51
|
+
(_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.onResponse) === null || _d === void 0 ? void 0 : _d.call(_c, request, response);
|
|
52
52
|
return response;
|
|
53
53
|
})).catch((error) => {
|
|
54
54
|
var _a, _b;
|
|
55
|
-
(_b = (_a = this.options).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
55
|
+
(_b = (_a = this.options).onError) === null || _b === void 0 ? void 0 : _b.call(_a, request, error);
|
|
56
56
|
throw error;
|
|
57
57
|
});
|
|
58
58
|
});
|
|
@@ -2,9 +2,9 @@ import Repository from "./Repository";
|
|
|
2
2
|
import { HttpRequest, HttpResponse } from "../api/Service";
|
|
3
3
|
export interface RestOptions {
|
|
4
4
|
interceptor?: (endpoint: string, request: HttpRequest) => HttpRequest | undefined;
|
|
5
|
-
onResponse?: (response: HttpResponse) => void;
|
|
6
|
-
onRawResponse?: (response: string) => void;
|
|
7
|
-
onError?: (error: Error) => void;
|
|
5
|
+
onResponse?: (request: HttpRequest, response: HttpResponse) => void;
|
|
6
|
+
onRawResponse?: (request: HttpRequest, response: string) => void;
|
|
7
|
+
onError?: (request: HttpRequest, error: Error) => void;
|
|
8
8
|
}
|
|
9
9
|
export default class RepositoryRest<Body = any, Res = any> extends Repository {
|
|
10
10
|
private readonly baseUrl;
|
package/package.json
CHANGED
|
@@ -4,9 +4,9 @@ import QueryUtils from "./utils/QueryUtils";
|
|
|
4
4
|
|
|
5
5
|
export interface RestOptions {
|
|
6
6
|
interceptor?: (endpoint: string, request: HttpRequest) => HttpRequest | undefined
|
|
7
|
-
onResponse?: (response: HttpResponse) => void;
|
|
8
|
-
onRawResponse?: (response: string) => void;
|
|
9
|
-
onError?: (error: Error) => void
|
|
7
|
+
onResponse?: (request: HttpRequest, response: HttpResponse) => void;
|
|
8
|
+
onRawResponse?: (request: HttpRequest, response: string) => void;
|
|
9
|
+
onError?: (request: HttpRequest, error: Error) => void
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export default class RepositoryRest<Body=any,Res=any> extends Repository
|
|
@@ -52,16 +52,16 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
|
|
|
52
52
|
return call.then(async (res: Response) => {
|
|
53
53
|
let headers: any = {}; res.headers.forEach((value, key) => headers[key] = value);
|
|
54
54
|
let rawResponse = await res.text();
|
|
55
|
-
this.options.onRawResponse?.(rawResponse);
|
|
55
|
+
this.options.onRawResponse?.(request, rawResponse);
|
|
56
56
|
let response: HttpResponse<E> = {
|
|
57
57
|
httpCode: res.status,
|
|
58
|
-
content: JSON.
|
|
58
|
+
content: JSON.parse(rawResponse) as E,
|
|
59
59
|
headers
|
|
60
60
|
};
|
|
61
|
-
this.options?.onResponse?.(response);
|
|
61
|
+
this.options?.onResponse?.(request, response);
|
|
62
62
|
return response;
|
|
63
63
|
}).catch((error) => {
|
|
64
|
-
this.options.onError?.(error);
|
|
64
|
+
this.options.onError?.(request, error);
|
|
65
65
|
throw error;
|
|
66
66
|
});
|
|
67
67
|
}
|