@gandalan/weblibs 1.1.5 → 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.
Files changed (2) hide show
  1. package/api/RESTClient.js +38 -10
  2. package/package.json +1 -1
package/api/RESTClient.js CHANGED
@@ -47,10 +47,11 @@ export class RESTClient
47
47
  {
48
48
  try
49
49
  {
50
+ this.axiosInstance = this.getNewAxiosInstance();
50
51
  const response = await this.axiosInstance.get(uri, this.getUrlOptions());
51
52
  this.lastError = "";
52
53
  return response.data;
53
- }
54
+ }
54
55
  catch (error)
55
56
  {
56
57
  this.handleError(error);
@@ -61,6 +62,7 @@ export class RESTClient
61
62
  {
62
63
  try
63
64
  {
65
+ this.axiosInstance = this.getNewAxiosInstance();
64
66
  const response = await this.axiosInstance.get(uri, { responseType: "blob" });
65
67
  let fileName = "1000.pdf";
66
68
  if (response.headers["content-disposition"])
@@ -82,6 +84,7 @@ export class RESTClient
82
84
  let response = {};
83
85
  try
84
86
  {
87
+ this.axiosInstance = this.getNewAxiosInstance();
85
88
  response = await this.axiosInstance.get(uri, this.getUrlOptions())
86
89
  this.lastError = "";
87
90
  }
@@ -96,6 +99,7 @@ export class RESTClient
96
99
  {
97
100
  try
98
101
  {
102
+ this.axiosInstance = this.getNewAxiosInstance();
99
103
  const response = await this.axiosInstance.post(uri, formData, this.getUrlOptions());
100
104
  this.lastError = "";
101
105
  return response;
@@ -110,6 +114,7 @@ export class RESTClient
110
114
  {
111
115
  try
112
116
  {
117
+ this.axiosInstance = this.getNewAxiosInstance();
113
118
  const response = await this.axiosInstance.put(uri, formData, this.getUrlOptions());
114
119
  this.lastError = "";
115
120
  return response;
@@ -124,6 +129,7 @@ export class RESTClient
124
129
  {
125
130
  try
126
131
  {
132
+ this.axiosInstance = this.getNewAxiosInstance();
127
133
  const response = await this.axiosInstance.delete(uri, this.getUrlOptions());
128
134
  this.lastError = "";
129
135
  return response;
@@ -134,17 +140,39 @@ export class RESTClient
134
140
  }
135
141
  }
136
142
 
137
- // eslint-disable-next-line no-unused-vars
138
- onError = (error, message) =>
139
- { };
143
+ getNewAxiosInstance()
144
+ {
145
+ return axios.create({
146
+ baseURL: this.settings.apiBaseurl,
147
+ headers: {
148
+ "Authorization": `Bearer ${currentToken}`,
149
+ },
150
+ });
151
+ }
140
152
 
141
153
  handleError(error)
142
154
  {
143
- let message = error ? error.message : "?";
144
- // eslint-disable-next-line no-console
145
- console.error(`API Error: ${message}`);
146
- this.lastError = message;
147
- this.onError(error, message);
148
- throw error;
155
+ if (error.response)
156
+ {
157
+ // The request was made and the server responded with a status code
158
+ // that falls out of the range of 2xx
159
+ console.log(error.response.data);
160
+ console.log(error.response.status);
161
+ console.log(error.response.headers);
162
+ }
163
+ else if (error.request)
164
+ {
165
+ // The request was made but no response was received
166
+ // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
167
+ // http.ClientRequest in node.js
168
+ console.log(error.request);
169
+ }
170
+ else
171
+ {
172
+ // Something happened in setting up the request that triggered an Error
173
+ console.log("Error", error.message);
174
+ }
175
+ console.log(error.config);
176
+ this.lastError = error;
149
177
  }
150
178
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gandalan/weblibs",
3
- "version": "1.1.5",
3
+ "version": "1.1.10",
4
4
  "description": "WebLibs for Gandalan JS/TS/Svelte projects",
5
5
  "keywords": [
6
6
  "gandalan"