@unito/integration-sdk 1.4.2 → 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.
package/dist/src/index.cjs
CHANGED
|
@@ -1366,7 +1366,7 @@ class Provider {
|
|
|
1366
1366
|
case 'TimeoutError':
|
|
1367
1367
|
throw this.handleError(408, 'Request timeout', options);
|
|
1368
1368
|
}
|
|
1369
|
-
throw this.handleError(500, `Unexpected error while calling the provider
|
|
1369
|
+
throw this.handleError(500, `Unexpected error while calling the provider. ErrorName: "${error.name}" \n message: "${error.message}" \n stack: ${error.stack} \n cause: ${error.cause} \n causeStack: ${error.cause?.stack}`, options);
|
|
1370
1370
|
}
|
|
1371
1371
|
throw this.handleError(500, 'Unexpected error while calling the provider - this is not normal, investigate', options);
|
|
1372
1372
|
}
|
|
@@ -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;
|
|
@@ -267,7 +267,7 @@ export class Provider {
|
|
|
267
267
|
case 'TimeoutError':
|
|
268
268
|
throw this.handleError(408, 'Request timeout', options);
|
|
269
269
|
}
|
|
270
|
-
throw this.handleError(500, `Unexpected error while calling the provider
|
|
270
|
+
throw this.handleError(500, `Unexpected error while calling the provider. ErrorName: "${error.name}" \n message: "${error.message}" \n stack: ${error.stack} \n cause: ${error.cause} \n causeStack: ${error.cause?.stack}`, options);
|
|
271
271
|
}
|
|
272
272
|
throw this.handleError(500, 'Unexpected error while calling the provider - this is not normal, investigate', options);
|
|
273
273
|
}
|
|
@@ -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,
|
|
@@ -553,7 +569,7 @@ describe('Provider', () => {
|
|
|
553
569
|
});
|
|
554
570
|
it('throws on unknown errors', async (context) => {
|
|
555
571
|
context.mock.method(global, 'fetch', () => {
|
|
556
|
-
throw new
|
|
572
|
+
throw new TypeError('foo', { cause: new Error('bar') });
|
|
557
573
|
});
|
|
558
574
|
let error;
|
|
559
575
|
try {
|
|
@@ -567,10 +583,12 @@ describe('Provider', () => {
|
|
|
567
583
|
error = e;
|
|
568
584
|
}
|
|
569
585
|
assert.ok(error instanceof HttpErrors.HttpError);
|
|
570
|
-
assert.ok(error.message.startsWith('Unexpected error while calling the provider
|
|
571
|
-
assert.ok(error.message.includes('
|
|
586
|
+
assert.ok(error.message.startsWith('Unexpected error while calling the provider.'));
|
|
587
|
+
assert.ok(error.message.includes('ErrorName: "TypeError"'));
|
|
572
588
|
assert.ok(error.message.includes('message: "foo"'));
|
|
573
589
|
assert.ok(error.message.includes('stack:'));
|
|
590
|
+
assert.ok(error.message.includes('cause:'));
|
|
591
|
+
assert.ok(error.message.includes('causeStack:'));
|
|
574
592
|
});
|
|
575
593
|
it('throws on status 429', async (context) => {
|
|
576
594
|
const response = new Response('response body', {
|
package/package.json
CHANGED
|
@@ -372,9 +372,10 @@ export class Provider {
|
|
|
372
372
|
case 'TimeoutError':
|
|
373
373
|
throw this.handleError(408, 'Request timeout', options);
|
|
374
374
|
}
|
|
375
|
+
|
|
375
376
|
throw this.handleError(
|
|
376
377
|
500,
|
|
377
|
-
`Unexpected error while calling the provider
|
|
378
|
+
`Unexpected error while calling the provider. ErrorName: "${error.name}" \n message: "${error.message}" \n stack: ${error.stack} \n cause: ${error.cause} \n causeStack: ${(error.cause as Error)?.stack}`,
|
|
378
379
|
options,
|
|
379
380
|
);
|
|
380
381
|
}
|
|
@@ -389,6 +390,9 @@ export class Provider {
|
|
|
389
390
|
if (response.status >= 400) {
|
|
390
391
|
const textResult = await response.text();
|
|
391
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 };
|
|
392
396
|
}
|
|
393
397
|
|
|
394
398
|
const responseContentType = response.headers.get('content-type');
|
|
@@ -406,7 +410,7 @@ export class Provider {
|
|
|
406
410
|
throw this.handleError(
|
|
407
411
|
500,
|
|
408
412
|
`Unsupported content-type, expected 'application/json' but got '${responseContentType}'.
|
|
409
|
-
Original response (${response.status}): ${textResult}`,
|
|
413
|
+
Original response (${response.status}): "${textResult}"`,
|
|
410
414
|
options,
|
|
411
415
|
);
|
|
412
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,
|
|
@@ -658,7 +682,7 @@ describe('Provider', () => {
|
|
|
658
682
|
|
|
659
683
|
it('throws on unknown errors', async context => {
|
|
660
684
|
context.mock.method(global, 'fetch', () => {
|
|
661
|
-
throw new
|
|
685
|
+
throw new TypeError('foo', { cause: new Error('bar') });
|
|
662
686
|
});
|
|
663
687
|
|
|
664
688
|
let error;
|
|
@@ -674,10 +698,12 @@ describe('Provider', () => {
|
|
|
674
698
|
}
|
|
675
699
|
|
|
676
700
|
assert.ok(error instanceof HttpErrors.HttpError);
|
|
677
|
-
assert.ok(error.message.startsWith('Unexpected error while calling the provider
|
|
678
|
-
assert.ok(error.message.includes('
|
|
701
|
+
assert.ok(error.message.startsWith('Unexpected error while calling the provider.'));
|
|
702
|
+
assert.ok(error.message.includes('ErrorName: "TypeError"'));
|
|
679
703
|
assert.ok(error.message.includes('message: "foo"'));
|
|
680
704
|
assert.ok(error.message.includes('stack:'));
|
|
705
|
+
assert.ok(error.message.includes('cause:'));
|
|
706
|
+
assert.ok(error.message.includes('causeStack:'));
|
|
681
707
|
});
|
|
682
708
|
|
|
683
709
|
it('throws on status 429', async context => {
|