@unito/integration-sdk 1.4.3 → 1.4.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.
@@ -1374,6 +1374,10 @@ class Provider {
1374
1374
  const textResult = await response.text();
1375
1375
  throw this.handleError(response.status, textResult, options);
1376
1376
  }
1377
+ else if (response.status === 204 || response.body === null) {
1378
+ // No content: return without inspecting the body
1379
+ return { status: response.status, headers: response.headers, body: undefined };
1380
+ }
1377
1381
  const responseContentType = response.headers.get('content-type');
1378
1382
  let body;
1379
1383
  if (options.rawBody || headers.Accept === 'application/octet-stream') {
@@ -1387,7 +1391,7 @@ class Provider {
1387
1391
  if (responseContentType && !responseContentType.includes('application/json')) {
1388
1392
  const textResult = await response.text();
1389
1393
  throw this.handleError(500, `Unsupported content-type, expected 'application/json' but got '${responseContentType}'.
1390
- Original response (${response.status}): ${textResult}`, options);
1394
+ Original response (${response.status}): "${textResult}"`, options);
1391
1395
  }
1392
1396
  try {
1393
1397
  body = response.body ? await response.json() : undefined;
@@ -275,6 +275,10 @@ export class Provider {
275
275
  const textResult = await response.text();
276
276
  throw this.handleError(response.status, textResult, options);
277
277
  }
278
+ else if (response.status === 204 || response.body === null) {
279
+ // No content: return without inspecting the body
280
+ return { status: response.status, headers: response.headers, body: undefined };
281
+ }
278
282
  const responseContentType = response.headers.get('content-type');
279
283
  let body;
280
284
  if (options.rawBody || headers.Accept === 'application/octet-stream') {
@@ -288,7 +292,7 @@ export class Provider {
288
292
  if (responseContentType && !responseContentType.includes('application/json')) {
289
293
  const textResult = await response.text();
290
294
  throw this.handleError(500, `Unsupported content-type, expected 'application/json' but got '${responseContentType}'.
291
- Original response (${response.status}): ${textResult}`, options);
295
+ Original response (${response.status}): "${textResult}"`, options);
292
296
  }
293
297
  try {
294
298
  body = response.body ? await response.json() : undefined;
@@ -452,6 +452,22 @@ describe('Provider', () => {
452
452
  assert.ok(providerResponse);
453
453
  assert.ok(providerResponse.body instanceof ReadableStream);
454
454
  });
455
+ it('returns successfully on unexpected content-type response with no body', async (context) => {
456
+ const response = new Response(null, {
457
+ status: 201,
458
+ headers: { 'Content-Type': 'html/text' },
459
+ });
460
+ context.mock.method(global, 'fetch', () => Promise.resolve(response));
461
+ const providerResponse = await provider.post('/endpoint/123', {}, {
462
+ credentials: { apiKey: 'apikey#1111' },
463
+ logger: logger,
464
+ signal: new AbortController().signal,
465
+ });
466
+ assert.ok(providerResponse);
467
+ assert.strictEqual(providerResponse.status, response.status);
468
+ assert.strictEqual(providerResponse.headers, response.headers);
469
+ assert.strictEqual(providerResponse.body, undefined);
470
+ });
455
471
  it('throws on invalid json response', async (context) => {
456
472
  const response = new Response('{invalidJSON}', {
457
473
  status: 200,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-sdk",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "Integration SDK",
5
5
  "type": "module",
6
6
  "types": "dist/src/index.d.ts",
@@ -390,6 +390,9 @@ export class Provider {
390
390
  if (response.status >= 400) {
391
391
  const textResult = await response.text();
392
392
  throw this.handleError(response.status, textResult, options);
393
+ } else if (response.status === 204 || response.body === null) {
394
+ // No content: return without inspecting the body
395
+ return { status: response.status, headers: response.headers, body: undefined as unknown as T };
393
396
  }
394
397
 
395
398
  const responseContentType = response.headers.get('content-type');
@@ -407,7 +410,7 @@ export class Provider {
407
410
  throw this.handleError(
408
411
  500,
409
412
  `Unsupported content-type, expected 'application/json' but got '${responseContentType}'.
410
- Original response (${response.status}): ${textResult}`,
413
+ Original response (${response.status}): "${textResult}"`,
411
414
  options,
412
415
  );
413
416
  }
@@ -539,6 +539,30 @@ describe('Provider', () => {
539
539
  assert.ok(providerResponse.body instanceof ReadableStream);
540
540
  });
541
541
 
542
+ it('returns successfully on unexpected content-type response with no body', async context => {
543
+ const response = new Response(null, {
544
+ status: 201,
545
+ headers: { 'Content-Type': 'html/text' },
546
+ });
547
+
548
+ context.mock.method(global, 'fetch', () => Promise.resolve(response));
549
+
550
+ const providerResponse = await provider.post(
551
+ '/endpoint/123',
552
+ {},
553
+ {
554
+ credentials: { apiKey: 'apikey#1111' },
555
+ logger: logger,
556
+ signal: new AbortController().signal,
557
+ },
558
+ );
559
+
560
+ assert.ok(providerResponse);
561
+ assert.strictEqual(providerResponse.status, response.status);
562
+ assert.strictEqual(providerResponse.headers, response.headers);
563
+ assert.strictEqual(providerResponse.body, undefined);
564
+ });
565
+
542
566
  it('throws on invalid json response', async context => {
543
567
  const response = new Response('{invalidJSON}', {
544
568
  status: 200,