attlaz-client 1.17.4 → 1.17.5
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,7 +41,7 @@ export class QueryString {
|
|
|
41
41
|
if (Array.isArray(value)) {
|
|
42
42
|
value = value.join(',');
|
|
43
43
|
}
|
|
44
|
-
output.push(parameter.parameter + '=' + value);
|
|
44
|
+
output.push(parameter.parameter + '=' + encodeURIComponent(value));
|
|
45
45
|
}
|
|
46
46
|
if (this.command.includes('?')) {
|
|
47
47
|
return this.command + '&' + output.join('&');
|
package/dist/Http/HttpClient.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// import {fetch} from 'popsicle';
|
|
2
1
|
import axios from 'axios';
|
|
3
2
|
import { HttpClientResponse } from './HttpClientResponse.js';
|
|
4
3
|
import { ClientError } from './ClientError.js';
|
|
@@ -14,8 +13,8 @@ export class HttpClient {
|
|
|
14
13
|
static HTTP_UNAVAILABLE = 503;
|
|
15
14
|
static HTTP_TIMEOUT = 504;
|
|
16
15
|
static async request(request) {
|
|
16
|
+
// TODo: should we catch axios error sand make them into ClientErrors?
|
|
17
17
|
const response = await HttpClient.axiosRequest(request);
|
|
18
|
-
// const response: HttpClientResponse = await HttpClient.superAgentRequest(request);
|
|
19
18
|
const error = ClientError.byStatus(response.status, response.statusText);
|
|
20
19
|
if (error !== null && error !== undefined) {
|
|
21
20
|
if (response.body !== null && response.body !== undefined && response.body.error !== null && response.body.error !== undefined && response.body.error.message !== null && response.body.error.message !== undefined) {
|
|
@@ -40,97 +39,9 @@ export class HttpClient {
|
|
|
40
39
|
const headerValue = rawResponse.headers[header];
|
|
41
40
|
httpResponse.headers[header] = headerValue === null ? '' : headerValue;
|
|
42
41
|
});
|
|
43
|
-
// console.log('Raw', rawResponse.data);
|
|
44
|
-
// console.log('Is json', HttpClient.isJson(httpResponse));
|
|
45
42
|
httpResponse.body = await rawResponse.data;
|
|
46
|
-
// if (HttpClient.isJson(httpResponse)) {
|
|
47
|
-
// let jsonData: object | null = null;
|
|
48
|
-
// if (httpResponse.body !== '') {
|
|
49
|
-
// try {
|
|
50
|
-
// jsonData = JSON.parse(httpResponse.body);
|
|
51
|
-
// } catch (e) {
|
|
52
|
-
// // console.error(, {statusText: httpResponse.statusText, error: e});
|
|
53
|
-
// throw new Error('Unable to parse response data to JSON');
|
|
54
|
-
// }
|
|
55
|
-
// }
|
|
56
|
-
// httpResponse.body = jsonData;
|
|
57
|
-
// } else {
|
|
58
|
-
// // response.body = rawData;
|
|
59
|
-
// }
|
|
60
43
|
return httpResponse;
|
|
61
44
|
}
|
|
62
|
-
// private static async popsicleRequest(request: HttpClientRequest): Promise<HttpClientResponse> {
|
|
63
|
-
// const rawRequest: CommonRequestOptions<any> = {
|
|
64
|
-
// url: request.getFullUrl(),
|
|
65
|
-
// method: request.method,
|
|
66
|
-
// headers: request.headers,
|
|
67
|
-
// omitDefaultHeaders: true,
|
|
68
|
-
// body: request.body,
|
|
69
|
-
// } as CommonRequestOptions<any>;
|
|
70
|
-
// const rawResponse: PopsicleResponse = await fetch(request.getFullUrl(), rawRequest);
|
|
71
|
-
// const httpResponse: HttpClientResponse = new HttpClientResponse(rawResponse.status, rawResponse.statusText);
|
|
72
|
-
// for (const header of rawResponse.headers.keys()) {
|
|
73
|
-
// const headerValue: string | null = rawResponse.headers.get(header);
|
|
74
|
-
// httpResponse.headers[header] = headerValue === null ? '' : headerValue;
|
|
75
|
-
// }
|
|
76
|
-
//
|
|
77
|
-
// httpResponse.body = await rawResponse.text();
|
|
78
|
-
// if (HttpClient.isJson(httpResponse)) {
|
|
79
|
-
// let jsonData: object | null = null;
|
|
80
|
-
// if (httpResponse.body !== '') {
|
|
81
|
-
// try {
|
|
82
|
-
// jsonData = JSON.parse(httpResponse.body);
|
|
83
|
-
// } catch (e) {
|
|
84
|
-
// // console.error(, {statusText: httpResponse.statusText, error: e});
|
|
85
|
-
// throw new Error('Unable to parse response data to JSON');
|
|
86
|
-
// }
|
|
87
|
-
// }
|
|
88
|
-
// httpResponse.body = jsonData;
|
|
89
|
-
// } else {
|
|
90
|
-
// // response.body = rawData;
|
|
91
|
-
// }
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
// return httpResponse;
|
|
95
|
-
// }
|
|
96
|
-
// private static async superAgentRequest(request: HttpClientRequest): Promise<HttpClientResponse> {
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
// let x: SuperAgent.Request | null = null;
|
|
100
|
-
// if (request.method === HttpClientRequest.GET) {
|
|
101
|
-
// x = SuperAgent.get(request.getFullUrl());
|
|
102
|
-
// } else if (request.method === HttpClientRequest.POST) {
|
|
103
|
-
// x = SuperAgent.post(request.getFullUrl());
|
|
104
|
-
//
|
|
105
|
-
// } else if (request.method === HttpClientRequest.PUT) {
|
|
106
|
-
// x = SuperAgent.put(request.getFullUrl());
|
|
107
|
-
// } else {
|
|
108
|
-
// throw new Error('Unknown request method `' + request.method + '`');
|
|
109
|
-
// }
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
// if (x === null) {
|
|
113
|
-
// throw new Error('Hm');
|
|
114
|
-
// }
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
// for (const key in request.headers) {
|
|
118
|
-
// if (Object.prototype.hasOwnProperty.call(request.headers, key)) {
|
|
119
|
-
// console.log('Set ' + key + ': ' + request.headers[key]);
|
|
120
|
-
// x.set(key, request.headers[key] as string);
|
|
121
|
-
// }
|
|
122
|
-
// }
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
// const rawResponse: SuperAgent.Response = await x.send(request.body);
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
// const response: HttpClientResponse = new HttpClientResponse(rawResponse.statusCode, '');
|
|
129
|
-
// response.body = rawResponse.body;
|
|
130
|
-
// // TODO: append/validate headers
|
|
131
|
-
// response.headers = rawResponse.headers;
|
|
132
|
-
// return response;
|
|
133
|
-
// }
|
|
134
45
|
static isJson(response) {
|
|
135
46
|
return response.getContentType() === 'application/json';
|
|
136
47
|
}
|