1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | };
|
9 | return function (d, b) {
|
10 | if (typeof b !== "function" && b !== null)
|
11 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
12 | extendStatics(d, b);
|
13 | function __() { this.constructor = d; }
|
14 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15 | };
|
16 | })();
|
17 | var __assign = (this && this.__assign) || function () {
|
18 | __assign = Object.assign || function(t) {
|
19 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
20 | s = arguments[i];
|
21 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
22 | t[p] = s[p];
|
23 | }
|
24 | return t;
|
25 | };
|
26 | return __assign.apply(this, arguments);
|
27 | };
|
28 | Object.defineProperty(exports, "__esModule", { value: true });
|
29 | exports.AxiosHttpClient = void 0;
|
30 | var axios_1 = require("axios");
|
31 | var models_1 = require("./models");
|
32 | var index_1 = require("./errors/index");
|
33 | var AxiosHttpClient = (function (_super) {
|
34 | __extends(AxiosHttpClient, _super);
|
35 | function AxiosHttpClient(configOptions) {
|
36 | var _this = _super.call(this, configOptions) || this;
|
37 | _this.errorHandler = new index_1.ErrorHandler();
|
38 | return _this;
|
39 | }
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 | AxiosHttpClient.prototype.initHttpClient = function (configOptions) {
|
46 | this.clientOptions = __assign(__assign({}, models_1.HttpClient.DefaultOptions), configOptions);
|
47 | var httpClient = axios_1.default.create({
|
48 | baseURL: this.getBaseHttpRequestURL(),
|
49 | timeout: this.getRequestTimeoutInMilliseconds(),
|
50 | responseType: "json",
|
51 | maxContentLength: Infinity,
|
52 | maxBodyLength: Infinity,
|
53 | validateStatus: function (status) {
|
54 | return status >= 200 && status < 300;
|
55 | },
|
56 | });
|
57 | httpClient.interceptors.response.use(function (response) { return (response.data); });
|
58 | this.client = httpClient;
|
59 | };
|
60 | |
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | AxiosHttpClient.prototype.httpRequest = function (method, path, queryParameters, body, requestHeaders) {
|
69 | var _this = this;
|
70 | return this.client.request({
|
71 | method: method,
|
72 | url: path,
|
73 | data: body,
|
74 | headers: requestHeaders,
|
75 | params: queryParameters,
|
76 | }).catch(function (errorThrown) {
|
77 | return Promise.reject(_this.transformError(errorThrown));
|
78 | });
|
79 | };
|
80 | |
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | AxiosHttpClient.prototype.transformError = function (errorThrown) {
|
88 | var response = errorThrown.response;
|
89 | if (response !== undefined) {
|
90 | var status_1 = this.adjustValue(0, response.status);
|
91 | var errorCode = this.adjustValue(0, response.data.ErrorCode);
|
92 | var message = this.adjustValue(errorThrown.message, response.data.Message);
|
93 | return this.errorHandler.buildError(message, errorCode, status_1);
|
94 | }
|
95 | else if (errorThrown.message !== undefined) {
|
96 | return this.errorHandler.buildError(errorThrown.message);
|
97 | }
|
98 | else {
|
99 | return this.errorHandler.buildError(JSON.stringify(errorThrown, Object.getOwnPropertyNames(errorThrown)));
|
100 | }
|
101 | };
|
102 | |
103 |
|
104 |
|
105 |
|
106 |
|
107 | AxiosHttpClient.prototype.getRequestTimeoutInMilliseconds = function () {
|
108 | return (this.clientOptions.timeout || 60) * 1000;
|
109 | };
|
110 | AxiosHttpClient.prototype.adjustValue = function (defaultValue, data) {
|
111 | return (data === undefined) ? defaultValue : data;
|
112 | };
|
113 | return AxiosHttpClient;
|
114 | }(models_1.HttpClient));
|
115 | exports.AxiosHttpClient = AxiosHttpClient;
|
116 |
|
\ | No newline at end of file |