whio-api-sdk 1.1.33 → 1.1.34
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.
|
@@ -67,6 +67,7 @@ export class BaseClient {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
request(endpoint, method = 'GET', body, headers = {}, noToken = false) {
|
|
70
|
+
var _a;
|
|
70
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
72
|
const url = `${this.baseUrl}${endpoint}`;
|
|
72
73
|
const defaultHeaders = {
|
|
@@ -79,14 +80,34 @@ export class BaseClient {
|
|
|
79
80
|
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
try {
|
|
84
|
+
const response = yield axios({
|
|
85
|
+
url,
|
|
86
|
+
method,
|
|
87
|
+
headers: Object.assign(Object.assign({}, defaultHeaders), headers),
|
|
88
|
+
data: body,
|
|
89
|
+
timeout: 5000,
|
|
90
|
+
});
|
|
91
|
+
return response.data;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
// Surface the server-provided error message (NestJS sends `{ message }`)
|
|
95
|
+
// instead of axios's generic "Request failed with status code 4xx", so the
|
|
96
|
+
// reason reaches the UI. The AxiosError is kept intact (response/status/
|
|
97
|
+
// isAxiosError) so callers can still branch on the type of failure.
|
|
98
|
+
if (axios.isAxiosError(error)) {
|
|
99
|
+
const data = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
100
|
+
const serverMessage = Array.isArray(data === null || data === void 0 ? void 0 : data.message)
|
|
101
|
+
? data === null || data === void 0 ? void 0 : data.message.join(', ')
|
|
102
|
+
: typeof (data === null || data === void 0 ? void 0 : data.message) === 'string'
|
|
103
|
+
? data.message
|
|
104
|
+
: undefined;
|
|
105
|
+
if (serverMessage) {
|
|
106
|
+
error.message = serverMessage;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
90
111
|
});
|
|
91
112
|
}
|
|
92
113
|
fileUploadRequest(endpoint, body, headers = {}, onProgress) {
|
package/package.json
CHANGED
|
@@ -80,15 +80,36 @@ export class BaseClient {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
try {
|
|
84
|
+
const response = await axios({
|
|
85
|
+
url,
|
|
86
|
+
method,
|
|
87
|
+
headers: { ...defaultHeaders, ...headers },
|
|
88
|
+
data: body,
|
|
89
|
+
timeout: 5000,
|
|
90
|
+
});
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
return response.data;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
// Surface the server-provided error message (NestJS sends `{ message }`)
|
|
95
|
+
// instead of axios's generic "Request failed with status code 4xx", so the
|
|
96
|
+
// reason reaches the UI. The AxiosError is kept intact (response/status/
|
|
97
|
+
// isAxiosError) so callers can still branch on the type of failure.
|
|
98
|
+
if (axios.isAxiosError(error)) {
|
|
99
|
+
const data = error.response?.data as
|
|
100
|
+
| { message?: string | string[] }
|
|
101
|
+
| undefined;
|
|
102
|
+
const serverMessage = Array.isArray(data?.message)
|
|
103
|
+
? data?.message.join(', ')
|
|
104
|
+
: typeof data?.message === 'string'
|
|
105
|
+
? data.message
|
|
106
|
+
: undefined;
|
|
107
|
+
if (serverMessage) {
|
|
108
|
+
error.message = serverMessage;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
92
113
|
}
|
|
93
114
|
|
|
94
115
|
protected async fileUploadRequest<T>(
|