@rebasepro/client 0.2.3 → 0.2.4

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/index.umd.js CHANGED
@@ -141,6 +141,13 @@
141
141
  } catch (e) {
142
142
  }
143
143
  }
144
+ const getErrorField = (obj, field) => {
145
+ const err = obj?.error;
146
+ if (err && typeof err === "object" && err !== null && field in err) {
147
+ return err[field];
148
+ }
149
+ return obj?.[field];
150
+ };
144
151
  if (res.status === 401 && onUnauthorizedHandler) {
145
152
  const retried = await onUnauthorizedHandler();
146
153
  if (retried) {
@@ -176,9 +183,9 @@
176
183
  }
177
184
  throw new RebaseApiError(
178
185
  retryRes.status,
179
- retryBody?.error?.message || retryBody?.message || fallbackMessage || `Request failed with status ${retryRes.status}`,
180
- retryBody?.error?.code || retryBody?.code,
181
- retryBody?.error?.details || retryBody?.details
186
+ String(getErrorField(retryBody, "message") || fallbackMessage || `Request failed with status ${retryRes.status}`),
187
+ getErrorField(retryBody, "code"),
188
+ getErrorField(retryBody, "details")
182
189
  );
183
190
  }
184
191
  return retryBody;
@@ -192,9 +199,9 @@
192
199
  }
193
200
  throw new RebaseApiError(
194
201
  res.status,
195
- body?.error?.message || body?.message || fallbackMessage || `Request failed with status ${res.status}`,
196
- body?.error?.code || body?.code,
197
- body?.error?.details || body?.details
202
+ String(getErrorField(body, "message") || fallbackMessage || `Request failed with status ${res.status}`),
203
+ getErrorField(body, "code"),
204
+ getErrorField(body, "details")
198
205
  );
199
206
  }
200
207
  return body;