@honeybadger-io/js 3.2.6 → 3.2.9

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.
@@ -254,7 +254,7 @@ function runAfterNotifyHandlers(notice, handlers, error) {
254
254
  return true;
255
255
  }
256
256
  // Returns a new object with properties from other object.
257
- function newObject(obj) {
257
+ function shallowClone(obj) {
258
258
  if (typeof (obj) !== 'object' || obj === null) {
259
259
  return {};
260
260
  }
@@ -281,8 +281,14 @@ function sanitize(obj, maxDepth) {
281
281
  return false;
282
282
  }
283
283
  function canSerialize(obj) {
284
- // Functions are TMI and Symbols can't convert to strings.
285
- if (/function|symbol/.test(typeof (obj))) {
284
+ var typeOfObj = typeof obj;
285
+ // Functions are TMI
286
+ if (/function/.test(typeOfObj)) {
287
+ // Let special toJSON method pass as it's used by JSON.stringify (#722)
288
+ return obj.name === 'toJSON';
289
+ }
290
+ // Symbols can't convert to strings.
291
+ if (/symbol/.test(typeOfObj)) {
286
292
  return false;
287
293
  }
288
294
  if (obj === null) {
@@ -309,7 +315,7 @@ function sanitize(obj, maxDepth) {
309
315
  }
310
316
  // Serialize inside arrays
311
317
  if (Array.isArray(obj)) {
312
- return obj.map(function (o) { return serialize(o, depth + 1); });
318
+ return obj.map(function (o) { return safeSerialize(o, depth + 1); });
313
319
  }
314
320
  // Serialize inside objects
315
321
  if (typeof (obj) === 'object') {
@@ -317,7 +323,7 @@ function sanitize(obj, maxDepth) {
317
323
  for (var k in obj) {
318
324
  var v = obj[k];
319
325
  if (Object.prototype.hasOwnProperty.call(obj, k) && (k != null) && (v != null)) {
320
- ret[k] = serialize(v, depth + 1);
326
+ ret[k] = safeSerialize(v, depth + 1);
321
327
  }
322
328
  }
323
329
  return ret;
@@ -325,7 +331,16 @@ function sanitize(obj, maxDepth) {
325
331
  // Return everything else untouched
326
332
  return obj;
327
333
  }
328
- return serialize(obj);
334
+ function safeSerialize(obj, depth) {
335
+ if (depth === void 0) { depth = 0; }
336
+ try {
337
+ return serialize(obj, depth);
338
+ }
339
+ catch (e) {
340
+ return "[ERROR] " + e;
341
+ }
342
+ }
343
+ return safeSerialize(obj);
329
344
  }
330
345
  function logger(client) {
331
346
  var log = function (method) {
@@ -364,7 +379,7 @@ function makeNotice(thing) {
364
379
  notice = merge(thing, { name: e.name, message: e.message, stack: e.stack });
365
380
  }
366
381
  else if (typeof thing === 'object') {
367
- notice = newObject(thing);
382
+ notice = shallowClone(thing);
368
383
  }
369
384
  else {
370
385
  var m = String(thing);
@@ -488,7 +503,7 @@ function formatCGIData(vars, prefix) {
488
503
  var notifier = {
489
504
  name: 'honeybadger-js',
490
505
  url: 'https://github.com/honeybadger-io/honeybadger-js',
491
- version: '3.2.6'
506
+ version: '3.2.9'
492
507
  };
493
508
  // Split at commas
494
509
  var TAG_SEPARATOR = /,/;
@@ -631,7 +646,7 @@ var Client = /** @class */ (function () {
631
646
  return;
632
647
  }
633
648
  opts = opts || {};
634
- var metadata = newObject(opts.metadata);
649
+ var metadata = shallowClone(opts.metadata);
635
650
  var category = opts.category || 'custom';
636
651
  var timestamp = new Date().toISOString();
637
652
  this.__breadcrumbs.push({
@@ -830,6 +845,11 @@ function errorHandler(err, req, _res, next) {
830
845
  }
831
846
  function lambdaHandler(handler) {
832
847
  return function lambdaHandler(event, context, callback) {
848
+ // in the case of an async handler, the length of the handler will be less than 3 (no callback function).
849
+ // if this is the case, we have to explicitly call the callback function from the function we are returning.
850
+ // we don't have to do that if the handler has third callback function parameter,
851
+ // because it will be called directly from inside the handler.
852
+ var shouldInvokeCallbackExplicitly = handler.length < 3;
833
853
  // eslint-disable-next-line prefer-rest-params
834
854
  var args = arguments;
835
855
  var dom = domain__default['default'].create();
@@ -850,7 +870,12 @@ function lambdaHandler(handler) {
850
870
  dom.run(function () {
851
871
  process.nextTick(function () {
852
872
  Promise.resolve(handler.apply(this, args))
853
- .then(function () { hb.clear(); })
873
+ .then(function (res) {
874
+ hb.clear();
875
+ if (shouldInvokeCallbackExplicitly) {
876
+ callback(null, res);
877
+ }
878
+ })
854
879
  .catch(hbHandler);
855
880
  });
856
881
  });
@@ -7,7 +7,7 @@ export declare function objectIsExtensible(obj: any): boolean;
7
7
  export declare function makeBacktrace(stack: string, shift?: number): BacktraceFrame[];
8
8
  export declare function runBeforeNotifyHandlers(notice: any, handlers: BeforeNotifyHandler[]): boolean;
9
9
  export declare function runAfterNotifyHandlers(notice: any, handlers: AfterNotifyHandler[], error?: any): boolean;
10
- export declare function newObject<T>(obj: T): T | Record<string, unknown>;
10
+ export declare function shallowClone<T>(obj: T): T | Record<string, unknown>;
11
11
  export declare function sanitize(obj: any, maxDepth?: number): any;
12
12
  export declare function logger(client: Client): Logger;
13
13
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@honeybadger-io/js",
3
- "version": "3.2.6",
3
+ "version": "3.2.9",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/honeybadger-io/honeybadger-js",
6
6
  "author": {
@@ -66,7 +66,7 @@
66
66
  "sinon": "^11.1.2",
67
67
  "supertest": "^6.1.6",
68
68
  "ts-jest": "^27.0.5",
69
- "tsd": "^0.17.0",
69
+ "tsd": "^0.18.0",
70
70
  "tslib": "^2.3.1",
71
71
  "typescript": "^4.3.5"
72
72
  },