@larisarozin/dodone-shared 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/dist/utils/ApiClient.js +60 -10
- package/package.json +1 -1
package/dist/utils/ApiClient.js
CHANGED
|
@@ -31,8 +31,18 @@ class ApiClient {
|
|
|
31
31
|
return __awaiter(this, arguments, void 0, function* (route, options = {}) {
|
|
32
32
|
const response = yield fetch(this.config.baseUrl + route, Object.assign(Object.assign({}, options), { headers: Object.assign({ Authorization: `Bearer ${this.config.token}` }, options.headers) }));
|
|
33
33
|
if (!response.ok) {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
// Read the error response body to get the detailed error message
|
|
35
|
+
try {
|
|
36
|
+
const errorBody = yield response.json();
|
|
37
|
+
const errorMessage = errorBody.message || `Failed to fetch ${route}: ${response.status} - ${response.statusText}`;
|
|
38
|
+
console.error(`Error fetching ${route}:`, response.status, errorMessage);
|
|
39
|
+
throw new Error(errorMessage);
|
|
40
|
+
}
|
|
41
|
+
catch (parseError) {
|
|
42
|
+
// If parsing fails, fall back to status text
|
|
43
|
+
console.error(`Error fetching ${route}:`, response.status, response.statusText);
|
|
44
|
+
throw new Error(`Failed to fetch ${route}: ${response.status} - ${response.statusText}`);
|
|
45
|
+
}
|
|
36
46
|
}
|
|
37
47
|
return response.json();
|
|
38
48
|
});
|
|
@@ -44,8 +54,18 @@ class ApiClient {
|
|
|
44
54
|
return __awaiter(this, arguments, void 0, function* (route, body, options = {}) {
|
|
45
55
|
const response = yield fetch(this.config.baseUrl + route, Object.assign(Object.assign({ method: 'POST' }, options), { headers: Object.assign({ 'Content-Type': 'application/json', Authorization: `Bearer ${this.config.token}` }, options.headers), body: body ? JSON.stringify(body) : undefined }));
|
|
46
56
|
if (!response.ok) {
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
// Read the error response body to get the detailed error message
|
|
58
|
+
try {
|
|
59
|
+
const errorBody = yield response.json();
|
|
60
|
+
const errorMessage = errorBody.message || `Failed to post ${route}: ${response.status} - ${response.statusText}`;
|
|
61
|
+
console.error(`Error posting ${route}:`, response.status, errorMessage);
|
|
62
|
+
throw new Error(errorMessage);
|
|
63
|
+
}
|
|
64
|
+
catch (parseError) {
|
|
65
|
+
// If parsing fails, fall back to status text
|
|
66
|
+
console.error(`Error posting ${route}:`, response.status, response.statusText);
|
|
67
|
+
throw new Error(`Failed to post ${route}: ${response.status} - ${response.statusText}`);
|
|
68
|
+
}
|
|
49
69
|
}
|
|
50
70
|
return response.json();
|
|
51
71
|
});
|
|
@@ -54,8 +74,18 @@ class ApiClient {
|
|
|
54
74
|
return __awaiter(this, arguments, void 0, function* (route, body, options = {}) {
|
|
55
75
|
const response = yield fetch(this.config.baseUrl + route, Object.assign(Object.assign({ method: 'POST' }, options), { headers: Object.assign({ Authorization: `Bearer ${this.config.token}` }, options.headers), body: body }));
|
|
56
76
|
if (!response.ok) {
|
|
57
|
-
|
|
58
|
-
|
|
77
|
+
// Read the error response body to get the detailed error message
|
|
78
|
+
try {
|
|
79
|
+
const errorBody = yield response.json();
|
|
80
|
+
const errorMessage = errorBody.message || `Failed to post multimedia ${route}: ${response.status} - ${response.statusText}`;
|
|
81
|
+
console.error(`Error posting multimedia ${route}:`, response.status, errorMessage);
|
|
82
|
+
throw new Error(errorMessage);
|
|
83
|
+
}
|
|
84
|
+
catch (parseError) {
|
|
85
|
+
// If parsing fails, fall back to status text
|
|
86
|
+
console.error(`Error posting multimedia ${route}:`, response.status, response.statusText);
|
|
87
|
+
throw new Error(`Failed to post multimedia ${route}: ${response.status} - ${response.statusText}`);
|
|
88
|
+
}
|
|
59
89
|
}
|
|
60
90
|
return response.json();
|
|
61
91
|
});
|
|
@@ -67,8 +97,18 @@ class ApiClient {
|
|
|
67
97
|
return __awaiter(this, arguments, void 0, function* (route, body, options = {}) {
|
|
68
98
|
const response = yield fetch(this.config.baseUrl + route, Object.assign(Object.assign({ method: 'PUT' }, options), { headers: Object.assign({ 'Content-Type': 'application/json', Authorization: `Bearer ${this.config.token}` }, options.headers), body: body ? JSON.stringify(body) : undefined }));
|
|
69
99
|
if (!response.ok) {
|
|
70
|
-
|
|
71
|
-
|
|
100
|
+
// Read the error response body to get the detailed error message
|
|
101
|
+
try {
|
|
102
|
+
const errorBody = yield response.json();
|
|
103
|
+
const errorMessage = errorBody.message || `Failed to update ${route}: ${response.status} - ${response.statusText}`;
|
|
104
|
+
console.error(`Error updating ${route}:`, response.status, errorMessage);
|
|
105
|
+
throw new Error(errorMessage);
|
|
106
|
+
}
|
|
107
|
+
catch (parseError) {
|
|
108
|
+
// If parsing fails, fall back to status text
|
|
109
|
+
console.error(`Error updating ${route}:`, response.status, response.statusText);
|
|
110
|
+
throw new Error(`Failed to update ${route}: ${response.status} - ${response.statusText}`);
|
|
111
|
+
}
|
|
72
112
|
}
|
|
73
113
|
return response.json();
|
|
74
114
|
});
|
|
@@ -80,8 +120,18 @@ class ApiClient {
|
|
|
80
120
|
return __awaiter(this, arguments, void 0, function* (route, options = {}) {
|
|
81
121
|
const response = yield fetch(this.config.baseUrl + route, Object.assign(Object.assign({ method: 'DELETE' }, options), { headers: Object.assign({ Authorization: `Bearer ${this.config.token}` }, options.headers) }));
|
|
82
122
|
if (!response.ok) {
|
|
83
|
-
|
|
84
|
-
|
|
123
|
+
// Read the error response body to get the detailed error message
|
|
124
|
+
try {
|
|
125
|
+
const errorBody = yield response.json();
|
|
126
|
+
const errorMessage = errorBody.message || `Failed to delete ${route}: ${response.status} - ${response.statusText}`;
|
|
127
|
+
console.error(`Error deleting ${route}:`, response.status, errorMessage);
|
|
128
|
+
throw new Error(errorMessage);
|
|
129
|
+
}
|
|
130
|
+
catch (parseError) {
|
|
131
|
+
// If parsing fails, fall back to status text
|
|
132
|
+
console.error(`Error deleting ${route}:`, response.status, response.statusText);
|
|
133
|
+
throw new Error(`Failed to delete ${route}: ${response.status} - ${response.statusText}`);
|
|
134
|
+
}
|
|
85
135
|
}
|
|
86
136
|
return response.json();
|
|
87
137
|
});
|