@orsetra/shared-ui 1.0.23 → 1.0.24
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/lib/http-client.ts +42 -4
- package/package.json +1 -1
package/lib/http-client.ts
CHANGED
|
@@ -56,7 +56,20 @@ class HttpClient {
|
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
if (!response.ok) {
|
|
59
|
-
|
|
59
|
+
// Try to extract error message from API response
|
|
60
|
+
let errorMessage = `Request failed: ${response.status}`;
|
|
61
|
+
try {
|
|
62
|
+
const errorBody = await response.json();
|
|
63
|
+
// Zitadel API returns { code, message, details } on error
|
|
64
|
+
if (errorBody?.message) {
|
|
65
|
+
errorMessage = errorBody.message;
|
|
66
|
+
} else if (errorBody?.error) {
|
|
67
|
+
errorMessage = errorBody.error;
|
|
68
|
+
}
|
|
69
|
+
} catch {
|
|
70
|
+
// If we can't parse JSON, use the default message
|
|
71
|
+
}
|
|
72
|
+
throw new Error(errorMessage);
|
|
60
73
|
}
|
|
61
74
|
|
|
62
75
|
if (response.status === 204) {
|
|
@@ -121,8 +134,23 @@ class HttpClient {
|
|
|
121
134
|
});
|
|
122
135
|
|
|
123
136
|
if (!response.ok) {
|
|
124
|
-
|
|
125
|
-
|
|
137
|
+
// Try to extract error message from API response
|
|
138
|
+
let errorMessage = `Upload failed: ${response.status} ${response.statusText}`;
|
|
139
|
+
try {
|
|
140
|
+
const errorBody = await response.json();
|
|
141
|
+
if (errorBody?.message) {
|
|
142
|
+
errorMessage = errorBody.message;
|
|
143
|
+
} else if (errorBody?.error) {
|
|
144
|
+
errorMessage = errorBody.error;
|
|
145
|
+
}
|
|
146
|
+
} catch {
|
|
147
|
+
// Try text if JSON fails
|
|
148
|
+
try {
|
|
149
|
+
const errorText = await response.text();
|
|
150
|
+
if (errorText) errorMessage = errorText;
|
|
151
|
+
} catch { /* ignore */ }
|
|
152
|
+
}
|
|
153
|
+
throw new Error(errorMessage);
|
|
126
154
|
}
|
|
127
155
|
|
|
128
156
|
if (response.status === 204) {
|
|
@@ -143,7 +171,17 @@ class HttpClient {
|
|
|
143
171
|
});
|
|
144
172
|
|
|
145
173
|
if (!response.ok) {
|
|
146
|
-
|
|
174
|
+
// Try to extract error message from API response
|
|
175
|
+
let errorMessage = `Download failed: ${response.status} ${response.statusText}`;
|
|
176
|
+
try {
|
|
177
|
+
const errorBody = await response.json();
|
|
178
|
+
if (errorBody?.message) {
|
|
179
|
+
errorMessage = errorBody.message;
|
|
180
|
+
} else if (errorBody?.error) {
|
|
181
|
+
errorMessage = errorBody.error;
|
|
182
|
+
}
|
|
183
|
+
} catch { /* ignore */ }
|
|
184
|
+
throw new Error(errorMessage);
|
|
147
185
|
}
|
|
148
186
|
|
|
149
187
|
return await response.blob();
|