attlaz-client 1.17.5 → 1.17.6
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/dist/Http/Data/QueryString.js +4 -0
- package/dist/Http/HttpClient.js +29 -11
- package/package.json +1 -1
|
@@ -8,6 +8,10 @@ export class QueryString {
|
|
|
8
8
|
this.command = command;
|
|
9
9
|
}
|
|
10
10
|
set(parameter, value) {
|
|
11
|
+
const existingParam = this.parameters.find((param) => param.parameter === parameter);
|
|
12
|
+
if (existingParam !== undefined) {
|
|
13
|
+
throw new Error('Param already defined');
|
|
14
|
+
}
|
|
11
15
|
this.parameters.push({ parameter, value });
|
|
12
16
|
}
|
|
13
17
|
addPagination(pagination) {
|
package/dist/Http/HttpClient.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
1
|
+
import axios, { AxiosError } from 'axios';
|
|
2
2
|
import { HttpClientResponse } from './HttpClientResponse.js';
|
|
3
3
|
import { ClientError } from './ClientError.js';
|
|
4
4
|
export class HttpClient {
|
|
@@ -13,7 +13,6 @@ export class HttpClient {
|
|
|
13
13
|
static HTTP_UNAVAILABLE = 503;
|
|
14
14
|
static HTTP_TIMEOUT = 504;
|
|
15
15
|
static async request(request) {
|
|
16
|
-
// TODo: should we catch axios error sand make them into ClientErrors?
|
|
17
16
|
const response = await HttpClient.axiosRequest(request);
|
|
18
17
|
const error = ClientError.byStatus(response.status, response.statusText);
|
|
19
18
|
if (error !== null && error !== undefined) {
|
|
@@ -29,18 +28,37 @@ export class HttpClient {
|
|
|
29
28
|
url: request.getFullUrl(),
|
|
30
29
|
method: request.method,
|
|
31
30
|
headers: request.headers,
|
|
32
|
-
data: request.body,
|
|
33
31
|
};
|
|
32
|
+
if (request.body !== null && request.body !== undefined) {
|
|
33
|
+
requestConfig.data = request.body;
|
|
34
|
+
}
|
|
34
35
|
// TODO: should we share this instance between requests?
|
|
35
36
|
const axiosInstance = axios.create();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
// TODo: should we catch axios error sand make them into ClientErrors?
|
|
38
|
+
try {
|
|
39
|
+
const rawResponse = await axiosInstance.request(requestConfig);
|
|
40
|
+
const httpResponse = new HttpClientResponse(rawResponse.status, rawResponse.statusText);
|
|
41
|
+
Object.keys(rawResponse.headers).forEach((header) => {
|
|
42
|
+
const headerValue = rawResponse.headers[header];
|
|
43
|
+
httpResponse.headers[header] = headerValue === null ? '' : headerValue;
|
|
44
|
+
});
|
|
45
|
+
httpResponse.body = await rawResponse.data;
|
|
46
|
+
return httpResponse;
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
if (e instanceof AxiosError) {
|
|
50
|
+
const status = e.status === undefined ? 500 : e.status;
|
|
51
|
+
const statusCode = e.code === undefined ? 'Error' : e.code;
|
|
52
|
+
const response = new HttpClientResponse(status, statusCode);
|
|
53
|
+
if (e.response !== undefined) {
|
|
54
|
+
response.body = e.response.data;
|
|
55
|
+
}
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
58
|
+
console.error('Unable to perform request', { error: e });
|
|
59
|
+
const response = new HttpClientResponse(500, '');
|
|
60
|
+
return response;
|
|
61
|
+
}
|
|
44
62
|
}
|
|
45
63
|
static isJson(response) {
|
|
46
64
|
return response.getContentType() === 'application/json';
|