@unito/integration-sdk 1.0.23 → 1.0.26

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.
@@ -117,6 +117,7 @@ class Logger {
117
117
  ...this.metadata,
118
118
  ...metadata,
119
119
  message,
120
+ status: logLevel,
120
121
  });
121
122
  if (process.env.NODE_ENV === 'development') {
122
123
  console[logLevel](JSON.stringify(processedMessage, null, 2));
@@ -1304,8 +1305,9 @@ class Provider {
1304
1305
  case 'TimeoutError':
1305
1306
  throw this.handleError(408, 'Request timeout');
1306
1307
  }
1308
+ throw this.handleError(500, `Unexpected error while calling the provider: name: "${error.name}" \n message: "${error.message}" \n stack: ${error.stack}`);
1307
1309
  }
1308
- throw this.handleError(500, `Unexpected error while calling the provider: "${error}"`);
1310
+ throw this.handleError(500, 'Unexpected error while calling the provider - this is not normal, investigate');
1309
1311
  }
1310
1312
  if (response.status >= 400) {
1311
1313
  const textResult = await response.text();
@@ -1334,7 +1336,7 @@ class Provider {
1334
1336
  body = response.body;
1335
1337
  }
1336
1338
  else {
1337
- throw this.handleError(500, 'Unsupported accept header');
1339
+ throw this.handleError(500, 'Unsupported Content-Type');
1338
1340
  }
1339
1341
  return { status: response.status, headers: response.headers, body };
1340
1342
  };
@@ -89,6 +89,7 @@ export default class Logger {
89
89
  ...this.metadata,
90
90
  ...metadata,
91
91
  message,
92
+ status: logLevel,
92
93
  });
93
94
  if (process.env.NODE_ENV === 'development') {
94
95
  console[logLevel](JSON.stringify(processedMessage, null, 2));
@@ -266,8 +266,9 @@ export class Provider {
266
266
  case 'TimeoutError':
267
267
  throw this.handleError(408, 'Request timeout');
268
268
  }
269
+ throw this.handleError(500, `Unexpected error while calling the provider: name: "${error.name}" \n message: "${error.message}" \n stack: ${error.stack}`);
269
270
  }
270
- throw this.handleError(500, `Unexpected error while calling the provider: "${error}"`);
271
+ throw this.handleError(500, 'Unexpected error while calling the provider - this is not normal, investigate');
271
272
  }
272
273
  if (response.status >= 400) {
273
274
  const textResult = await response.text();
@@ -296,7 +297,7 @@ export class Provider {
296
297
  body = response.body;
297
298
  }
298
299
  else {
299
- throw this.handleError(500, 'Unsupported accept header');
300
+ throw this.handleError(500, 'Unsupported Content-Type');
300
301
  }
301
302
  return { status: response.status, headers: response.headers, body };
302
303
  };
@@ -33,35 +33,35 @@ describe('Logger', () => {
33
33
  logger.log('test');
34
34
  assert.strictEqual(logSpy.mock.calls.length, 1);
35
35
  assert.deepEqual(logSpy.mock.calls[0]?.arguments, [
36
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
36
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'log' }),
37
37
  ]);
38
38
  const errorSpy = testContext.mock.method(global.console, 'error', () => { });
39
39
  assert.strictEqual(errorSpy.mock.calls.length, 0);
40
40
  logger.error('test');
41
41
  assert.strictEqual(errorSpy.mock.calls.length, 1);
42
42
  assert.deepEqual(errorSpy.mock.calls[0]?.arguments, [
43
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
43
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'error' }),
44
44
  ]);
45
45
  const warnSpy = testContext.mock.method(global.console, 'warn', () => { });
46
46
  assert.strictEqual(warnSpy.mock.calls.length, 0);
47
47
  logger.warn('test');
48
48
  assert.strictEqual(warnSpy.mock.calls.length, 1);
49
49
  assert.deepEqual(warnSpy.mock.calls[0]?.arguments, [
50
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
50
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'warn' }),
51
51
  ]);
52
52
  const infoSpy = testContext.mock.method(global.console, 'info', () => { });
53
53
  assert.strictEqual(infoSpy.mock.calls.length, 0);
54
54
  logger.info('test');
55
55
  assert.strictEqual(infoSpy.mock.calls.length, 1);
56
56
  assert.deepEqual(infoSpy.mock.calls[0]?.arguments, [
57
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
57
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'info' }),
58
58
  ]);
59
59
  const debugSpy = testContext.mock.method(global.console, 'debug', () => { });
60
60
  assert.strictEqual(debugSpy.mock.calls.length, 0);
61
61
  logger.debug('test');
62
62
  assert.strictEqual(debugSpy.mock.calls.length, 1);
63
63
  assert.deepEqual(debugSpy.mock.calls[0]?.arguments, [
64
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
64
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'debug' }),
65
65
  ]);
66
66
  });
67
67
  it('merges message payload with metadata', testContext => {
@@ -77,6 +77,7 @@ describe('Logger', () => {
77
77
  http: { method: 'GET' },
78
78
  error: { code: '200', message: 'Page Not Found' },
79
79
  message: 'test',
80
+ status: 'log',
80
81
  }),
81
82
  ]);
82
83
  });
@@ -92,6 +93,7 @@ describe('Logger', () => {
92
93
  correlation_id: '123456789',
93
94
  http: { status_code: 200 },
94
95
  message: 'test',
96
+ status: 'log',
95
97
  }),
96
98
  ]);
97
99
  });
@@ -108,6 +110,7 @@ describe('Logger', () => {
108
110
  http: { method: 'GET', status_code: 200 },
109
111
  error_context: { error_code: 200, error_message: 'Page Not Found' },
110
112
  message: 'test',
113
+ status: 'log',
111
114
  }),
112
115
  ]);
113
116
  });
@@ -478,7 +478,10 @@ describe('Provider', () => {
478
478
  error = e;
479
479
  }
480
480
  assert.ok(error instanceof HttpErrors.HttpError);
481
- assert.equal(error.message, 'Unexpected error while calling the provider: "Error: foo"');
481
+ assert.ok(error.message.startsWith('Unexpected error while calling the provider:'));
482
+ assert.ok(error.message.includes('name: "Error"'));
483
+ assert.ok(error.message.includes('message: "foo"'));
484
+ assert.ok(error.message.includes('stack:'));
482
485
  });
483
486
  it('throws on status 429', async (context) => {
484
487
  const response = new Response('response body', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-sdk",
3
- "version": "1.0.23",
3
+ "version": "1.0.26",
4
4
  "description": "Integration SDK",
5
5
  "type": "module",
6
6
  "types": "dist/src/index.d.ts",
@@ -111,6 +111,7 @@ export default class Logger {
111
111
  ...this.metadata,
112
112
  ...metadata,
113
113
  message,
114
+ status: logLevel,
114
115
  });
115
116
 
116
117
  if (process.env.NODE_ENV === 'development') {
@@ -357,9 +357,13 @@ export class Provider {
357
357
  case 'TimeoutError':
358
358
  throw this.handleError(408, 'Request timeout');
359
359
  }
360
+ throw this.handleError(
361
+ 500,
362
+ `Unexpected error while calling the provider: name: "${error.name}" \n message: "${error.message}" \n stack: ${error.stack}`,
363
+ );
360
364
  }
361
365
 
362
- throw this.handleError(500, `Unexpected error while calling the provider: "${error}"`);
366
+ throw this.handleError(500, 'Unexpected error while calling the provider - this is not normal, investigate');
363
367
  }
364
368
 
365
369
  if (response.status >= 400) {
@@ -392,7 +396,7 @@ export class Provider {
392
396
  // When we expect octet-stream, we accept any Content-Type the provider sends us, we just want to stream it.
393
397
  body = response.body as T;
394
398
  } else {
395
- throw this.handleError(500, 'Unsupported accept header');
399
+ throw this.handleError(500, 'Unsupported Content-Type');
396
400
  }
397
401
 
398
402
  return { status: response.status, headers: response.headers, body };
@@ -42,7 +42,7 @@ describe('Logger', () => {
42
42
  logger.log('test');
43
43
  assert.strictEqual(logSpy.mock.calls.length, 1);
44
44
  assert.deepEqual(logSpy.mock.calls[0]?.arguments, [
45
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
45
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'log' }),
46
46
  ]);
47
47
 
48
48
  const errorSpy = testContext.mock.method(global.console, 'error', () => {});
@@ -50,7 +50,7 @@ describe('Logger', () => {
50
50
  logger.error('test');
51
51
  assert.strictEqual(errorSpy.mock.calls.length, 1);
52
52
  assert.deepEqual(errorSpy.mock.calls[0]?.arguments, [
53
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
53
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'error' }),
54
54
  ]);
55
55
 
56
56
  const warnSpy = testContext.mock.method(global.console, 'warn', () => {});
@@ -58,7 +58,7 @@ describe('Logger', () => {
58
58
  logger.warn('test');
59
59
  assert.strictEqual(warnSpy.mock.calls.length, 1);
60
60
  assert.deepEqual(warnSpy.mock.calls[0]?.arguments, [
61
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
61
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'warn' }),
62
62
  ]);
63
63
 
64
64
  const infoSpy = testContext.mock.method(global.console, 'info', () => {});
@@ -66,7 +66,7 @@ describe('Logger', () => {
66
66
  logger.info('test');
67
67
  assert.strictEqual(infoSpy.mock.calls.length, 1);
68
68
  assert.deepEqual(infoSpy.mock.calls[0]?.arguments, [
69
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
69
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'info' }),
70
70
  ]);
71
71
 
72
72
  const debugSpy = testContext.mock.method(global.console, 'debug', () => {});
@@ -74,7 +74,7 @@ describe('Logger', () => {
74
74
  logger.debug('test');
75
75
  assert.strictEqual(debugSpy.mock.calls.length, 1);
76
76
  assert.deepEqual(debugSpy.mock.calls[0]?.arguments, [
77
- JSON.stringify({ correlation_id: '123456789', message: 'test' }),
77
+ JSON.stringify({ correlation_id: '123456789', message: 'test', status: 'debug' }),
78
78
  ]);
79
79
  });
80
80
 
@@ -92,6 +92,7 @@ describe('Logger', () => {
92
92
  http: { method: 'GET' },
93
93
  error: { code: '200', message: 'Page Not Found' },
94
94
  message: 'test',
95
+ status: 'log',
95
96
  }),
96
97
  ]);
97
98
  });
@@ -109,6 +110,7 @@ describe('Logger', () => {
109
110
  correlation_id: '123456789',
110
111
  http: { status_code: 200 },
111
112
  message: 'test',
113
+ status: 'log',
112
114
  }),
113
115
  ]);
114
116
  });
@@ -127,6 +129,7 @@ describe('Logger', () => {
127
129
  http: { method: 'GET', status_code: 200 },
128
130
  error_context: { error_code: 200, error_message: 'Page Not Found' },
129
131
  message: 'test',
132
+ status: 'log',
130
133
  }),
131
134
  ]);
132
135
  });
@@ -569,7 +569,10 @@ describe('Provider', () => {
569
569
  }
570
570
 
571
571
  assert.ok(error instanceof HttpErrors.HttpError);
572
- assert.equal(error.message, 'Unexpected error while calling the provider: "Error: foo"');
572
+ assert.ok(error.message.startsWith('Unexpected error while calling the provider:'));
573
+ assert.ok(error.message.includes('name: "Error"'));
574
+ assert.ok(error.message.includes('message: "foo"'));
575
+ assert.ok(error.message.includes('stack:'));
573
576
  });
574
577
 
575
578
  it('throws on status 429', async context => {