@gandalan/weblibs 1.1.9 → 1.1.10
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/api/RESTClient.js +27 -27
- package/package.json +1 -1
package/api/RESTClient.js
CHANGED
|
@@ -8,7 +8,7 @@ export class RESTClient
|
|
|
8
8
|
axiosInstance = null;
|
|
9
9
|
|
|
10
10
|
constructor(settings)
|
|
11
|
-
{
|
|
11
|
+
{
|
|
12
12
|
this.settings = settings;
|
|
13
13
|
|
|
14
14
|
this.axiosInstance = axios.create({
|
|
@@ -39,34 +39,34 @@ export class RESTClient
|
|
|
39
39
|
}*/
|
|
40
40
|
|
|
41
41
|
getUrlOptions()
|
|
42
|
-
{
|
|
42
|
+
{
|
|
43
43
|
return { withCredentials: false };
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
async get(uri)
|
|
47
|
-
{
|
|
47
|
+
{
|
|
48
48
|
try
|
|
49
|
-
{
|
|
49
|
+
{
|
|
50
50
|
this.axiosInstance = this.getNewAxiosInstance();
|
|
51
51
|
const response = await this.axiosInstance.get(uri, this.getUrlOptions());
|
|
52
52
|
this.lastError = "";
|
|
53
53
|
return response.data;
|
|
54
|
-
|
|
54
|
+
}
|
|
55
55
|
catch (error)
|
|
56
|
-
{
|
|
56
|
+
{
|
|
57
57
|
this.handleError(error);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
async getFile(uri)
|
|
62
|
-
{
|
|
62
|
+
{
|
|
63
63
|
try
|
|
64
|
-
{
|
|
64
|
+
{
|
|
65
65
|
this.axiosInstance = this.getNewAxiosInstance();
|
|
66
66
|
const response = await this.axiosInstance.get(uri, { responseType: "blob" });
|
|
67
67
|
let fileName = "1000.pdf";
|
|
68
68
|
if (response.headers["content-disposition"])
|
|
69
|
-
{
|
|
69
|
+
{
|
|
70
70
|
fileName = response.headers["content-disposition"].split(";")[1];
|
|
71
71
|
fileName = fileName.replace("filename=", "").trim();
|
|
72
72
|
}
|
|
@@ -74,74 +74,74 @@ export class RESTClient
|
|
|
74
74
|
return { data: response.data, filename: fileName, contentType: "application/pdf" };
|
|
75
75
|
}
|
|
76
76
|
catch (error)
|
|
77
|
-
{
|
|
77
|
+
{
|
|
78
78
|
this.handleError(error);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
async getRaw(uri)
|
|
83
|
-
{
|
|
83
|
+
{
|
|
84
84
|
let response = {};
|
|
85
85
|
try
|
|
86
|
-
{
|
|
86
|
+
{
|
|
87
87
|
this.axiosInstance = this.getNewAxiosInstance();
|
|
88
88
|
response = await this.axiosInstance.get(uri, this.getUrlOptions())
|
|
89
89
|
this.lastError = "";
|
|
90
90
|
}
|
|
91
91
|
catch (error)
|
|
92
|
-
{
|
|
92
|
+
{
|
|
93
93
|
this.handleError(error);
|
|
94
94
|
}
|
|
95
95
|
return response;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
async post(uri, formData)
|
|
99
|
-
{
|
|
99
|
+
{
|
|
100
100
|
try
|
|
101
|
-
{
|
|
101
|
+
{
|
|
102
102
|
this.axiosInstance = this.getNewAxiosInstance();
|
|
103
103
|
const response = await this.axiosInstance.post(uri, formData, this.getUrlOptions());
|
|
104
104
|
this.lastError = "";
|
|
105
105
|
return response;
|
|
106
106
|
}
|
|
107
107
|
catch (error)
|
|
108
|
-
{
|
|
108
|
+
{
|
|
109
109
|
this.handleError(error);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
async put(uri, formData)
|
|
114
|
-
{
|
|
114
|
+
{
|
|
115
115
|
try
|
|
116
|
-
{
|
|
116
|
+
{
|
|
117
117
|
this.axiosInstance = this.getNewAxiosInstance();
|
|
118
118
|
const response = await this.axiosInstance.put(uri, formData, this.getUrlOptions());
|
|
119
119
|
this.lastError = "";
|
|
120
120
|
return response;
|
|
121
121
|
}
|
|
122
122
|
catch (error)
|
|
123
|
-
{
|
|
123
|
+
{
|
|
124
124
|
this.handleError(error);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
async delete(uri)
|
|
129
|
-
{
|
|
129
|
+
{
|
|
130
130
|
try
|
|
131
|
-
{
|
|
131
|
+
{
|
|
132
132
|
this.axiosInstance = this.getNewAxiosInstance();
|
|
133
133
|
const response = await this.axiosInstance.delete(uri, this.getUrlOptions());
|
|
134
134
|
this.lastError = "";
|
|
135
135
|
return response;
|
|
136
136
|
}
|
|
137
137
|
catch (error)
|
|
138
|
-
{
|
|
138
|
+
{
|
|
139
139
|
this.handleError(error);
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
getNewAxiosInstance()
|
|
144
|
-
{
|
|
144
|
+
{
|
|
145
145
|
return axios.create({
|
|
146
146
|
baseURL: this.settings.apiBaseurl,
|
|
147
147
|
headers: {
|
|
@@ -151,9 +151,9 @@ export class RESTClient
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
handleError(error)
|
|
154
|
-
{
|
|
154
|
+
{
|
|
155
155
|
if (error.response)
|
|
156
|
-
{
|
|
156
|
+
{
|
|
157
157
|
// The request was made and the server responded with a status code
|
|
158
158
|
// that falls out of the range of 2xx
|
|
159
159
|
console.log(error.response.data);
|
|
@@ -161,14 +161,14 @@ export class RESTClient
|
|
|
161
161
|
console.log(error.response.headers);
|
|
162
162
|
}
|
|
163
163
|
else if (error.request)
|
|
164
|
-
{
|
|
164
|
+
{
|
|
165
165
|
// The request was made but no response was received
|
|
166
166
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
|
167
167
|
// http.ClientRequest in node.js
|
|
168
168
|
console.log(error.request);
|
|
169
169
|
}
|
|
170
170
|
else
|
|
171
|
-
{
|
|
171
|
+
{
|
|
172
172
|
// Something happened in setting up the request that triggered an Error
|
|
173
173
|
console.log("Error", error.message);
|
|
174
174
|
}
|