@dexyn/common-library 1.1.5 → 1.1.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/api/apiClientUtils.js +5 -5
- package/package.json +1 -1
package/api/apiClientUtils.js
CHANGED
@@ -50,15 +50,15 @@ const createApiClient = (basePath, debugMode = false) => {
|
|
50
50
|
logger_1.logger.log(`Response status: ${response.status}`, debugMode);
|
51
51
|
logger_1.logger.log(`Response headers: ${JSON.stringify(Object.fromEntries(response.headers.entries()))}`, debugMode);
|
52
52
|
logger_1.logger.log(`Response URL: ${response.url}`, debugMode);
|
53
|
+
const responseBody = await response.text();
|
54
|
+
logger_1.logger.log(`Response body: ${responseBody}`, debugMode);
|
53
55
|
if (!response.ok) {
|
54
|
-
const errorData =
|
56
|
+
const errorData = JSON.parse(responseBody);
|
55
57
|
return errorData;
|
56
58
|
}
|
57
59
|
// Handle no content for 202 or other no-body status codes
|
58
60
|
if (response.status === 202 || response.status === 204 || !response.headers.get('Content-Type')) {
|
59
|
-
const body =
|
60
|
-
logger_1.logger.log(`Response body: ${JSON.stringify(e)}`, debugMode);
|
61
|
-
}); // Safely attempt to parse body
|
61
|
+
const body = JSON.parse(responseBody || '{}');
|
62
62
|
// Check if body is not an empty object
|
63
63
|
if (body && Object.keys(body).length > 0) {
|
64
64
|
return body;
|
@@ -66,7 +66,7 @@ const createApiClient = (basePath, debugMode = false) => {
|
|
66
66
|
return {}; // Return empty object if no content or empty object
|
67
67
|
}
|
68
68
|
// Return parsed JSON for non-void responses
|
69
|
-
return
|
69
|
+
return JSON.parse(responseBody);
|
70
70
|
};
|
71
71
|
return {
|
72
72
|
get: (endpoint, queryParameters = {}, pathParameters = {}, headers) => request(endpoint, { method: 'GET', headers }, queryParameters, pathParameters),
|