@unboundcx/sdk 2.6.3 → 2.6.5

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.
Files changed (2) hide show
  1. package/base.js +30 -5
  2. package/package.json +1 -1
package/base.js CHANGED
@@ -84,6 +84,11 @@ export class BaseSDK {
84
84
  throw new Error('Transport must have a request method');
85
85
  }
86
86
 
87
+ // Transport plugins must follow these rules:
88
+ // 1. RETURN API responses normally (including error status codes like 400, 500)
89
+ // 2. ONLY THROW exceptions for transport mechanism failures (connection issues, plugin errors)
90
+ // This ensures API errors flow through unchanged, same as built-in fetch
91
+
87
92
  const priority = transport.getPriority ? transport.getPriority() : 50;
88
93
  const name = transport.name || `transport_${Date.now()}`;
89
94
 
@@ -187,15 +192,23 @@ export class BaseSDK {
187
192
 
188
193
  return result;
189
194
  } catch (err) {
190
- // Debug logging for transport plugin failures
195
+ // IMPORTANT: This catch block should ONLY handle transport-level failures
196
+ // (e.g., WebSocket disconnected, plugin unavailable, network errors)
197
+ //
198
+ // Transport plugins should:
199
+ // - RETURN API error responses normally (400, 500, etc.) as response objects
200
+ // - ONLY THROW for transport mechanism failures
201
+ //
202
+ // This ensures API errors are passed through unchanged, just like built-in fetch
203
+
191
204
  if (this.debugMode) {
192
- console.log(`API :: ${transport.name} :: ${method.toUpperCase()} :: ${endpoint} :: ERROR :: ${err.message}`);
205
+ console.log(`API :: Transport ${transport.name} failure :: ${method.toUpperCase()} :: ${endpoint} :: ${err.message}`);
193
206
  }
194
207
  console.warn(
195
- `Transport ${transport.name} failed, falling back to HTTP:`,
208
+ `Transport ${transport.name} mechanism failed, falling back to HTTP:`,
196
209
  err.message,
197
210
  );
198
- // Fall through to HTTP
211
+ // Fall through to built-in HTTP fetch
199
212
  }
200
213
  }
201
214
 
@@ -292,7 +305,19 @@ export class BaseSDK {
292
305
  }
293
306
 
294
307
  const response = await fetch(url, options);
295
- const bodyResponse = await response.json();
308
+
309
+ // Check content type to determine how to parse the response
310
+ const contentType = response.headers.get('content-type') || '';
311
+ let bodyResponse;
312
+
313
+ if (contentType.includes('application/json')) {
314
+ bodyResponse = await response.json();
315
+ } else if (contentType.includes('text/')) {
316
+ bodyResponse = await response.text();
317
+ } else {
318
+ // For binary content (PDFs, images, etc), return as ArrayBuffer
319
+ bodyResponse = await response.arrayBuffer();
320
+ }
296
321
 
297
322
  const responseHeaders = response.headers;
298
323
  const responseRequestId =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "2.6.3",
3
+ "version": "2.6.5",
4
4
  "description": "Official JavaScript SDK for the Unbound API - A comprehensive toolkit for integrating with Unbound's communication, AI, and data management services",
5
5
  "main": "index.js",
6
6
  "type": "module",