@naturalcycles/backend-lib 4.14.0 → 4.14.2

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.
@@ -81,14 +81,11 @@ class SentrySharedService {
81
81
  // It's a Breadcrumb, not a console.log, because console.log are NOT automatically attached as Breadcrumbs in cron-job environments (outside of Express)
82
82
  this.sentry().addBreadcrumb({
83
83
  message: (0, nodejs_lib_1.inspectAny)(err, {
84
- includeErrorData: true,
85
84
  colors: false,
86
85
  }),
87
86
  // data: (err as AppError).data, // included in message
88
87
  });
89
- return this.sentry().captureException((0, js_lib_1._anyToError)(err, Error, {}, {
90
- stringifyFn: nodejs_lib_1.inspectAnyStringifyFn,
91
- }));
88
+ return this.sentry().captureException((0, js_lib_1._anyToError)(err));
92
89
  }
93
90
  /**
94
91
  * Returns "eventId"
@@ -114,16 +111,13 @@ class SentrySharedService {
114
111
  error: (...args) => {
115
112
  const message = args
116
113
  .map(arg => (0, nodejs_lib_1.inspectAny)(arg, {
117
- includeErrorData: true,
118
114
  colors: false,
119
115
  }))
120
116
  .join(' ');
121
117
  this.sentry().addBreadcrumb({
122
118
  message,
123
119
  });
124
- this.sentry().captureException((0, js_lib_1._anyToError)(args.length === 1 ? args[0] : args, Error, {}, {
125
- stringifyFn: nodejs_lib_1.inspectAnyStringifyFn,
126
- }));
120
+ this.sentry().captureException((0, js_lib_1._anyToError)(args.length === 1 ? args[0] : args));
127
121
  },
128
122
  };
129
123
  }
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.respondWithError = exports.genericErrorMiddleware = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
6
5
  const { APP_ENV } = process.env;
7
6
  const includeErrorStack = APP_ENV !== 'prod' && APP_ENV !== 'test';
8
7
  // Hacky way to store the sentryService, so it's available to `respondWithError` function
@@ -42,16 +41,16 @@ function respondWithError(req, res, err) {
42
41
  else {
43
42
  req.error(err);
44
43
  }
45
- const originalError = (0, js_lib_1._anyToError)(err, Error, {}, {
46
- stringifyFn: nodejs_lib_1.inspectAnyStringifyFn,
47
- });
44
+ const originalError = (0, js_lib_1._anyToError)(err);
48
45
  let errorId;
49
46
  if (sentryService && shouldReportToSentry(originalError)) {
50
47
  errorId = sentryService.captureException(originalError, false);
51
48
  }
52
49
  if (res.headersSent)
53
50
  return;
54
- const httpError = (0, js_lib_1._errorToErrorObject)(originalError, includeErrorStack);
51
+ const httpError = (0, js_lib_1._errorToErrorObject)(originalError);
52
+ if (!includeErrorStack)
53
+ delete httpError.stack;
55
54
  httpError.data.errorId = errorId;
56
55
  httpError.data.httpStatusCode ||= 500; // default to 500
57
56
  httpError.data.headersSent = headersSent || undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
- "version": "4.14.0",
3
+ "version": "4.14.2",
4
4
  "scripts": {
5
5
  "prepare": "husky install && patch-package",
6
6
  "serve": "APP_ENV=dev nodemon",
@@ -1,5 +1,5 @@
1
1
  import { _anyToError, _Memo, CommonLogger, CommonLogLevel } from '@naturalcycles/js-lib'
2
- import { inspectAny, inspectAnyStringifyFn } from '@naturalcycles/nodejs-lib'
2
+ import { inspectAny } from '@naturalcycles/nodejs-lib'
3
3
  import type { Breadcrumb, NodeOptions, SeverityLevel } from '@sentry/node'
4
4
  import type * as SentryLib from '@sentry/node'
5
5
  import { BackendErrorRequestHandler, BackendRequestHandler, getRequestLogger } from '../index'
@@ -93,22 +93,12 @@ export class SentrySharedService {
93
93
  // It's a Breadcrumb, not a console.log, because console.log are NOT automatically attached as Breadcrumbs in cron-job environments (outside of Express)
94
94
  this.sentry().addBreadcrumb({
95
95
  message: inspectAny(err, {
96
- includeErrorData: true,
97
96
  colors: false,
98
97
  }),
99
98
  // data: (err as AppError).data, // included in message
100
99
  })
101
100
 
102
- return this.sentry().captureException(
103
- _anyToError(
104
- err,
105
- Error,
106
- {},
107
- {
108
- stringifyFn: inspectAnyStringifyFn,
109
- },
110
- ),
111
- )
101
+ return this.sentry().captureException(_anyToError(err))
112
102
  }
113
103
 
114
104
  /**
@@ -138,7 +128,6 @@ export class SentrySharedService {
138
128
  const message = args
139
129
  .map(arg =>
140
130
  inspectAny(arg, {
141
- includeErrorData: true,
142
131
  colors: false,
143
132
  }),
144
133
  )
@@ -148,16 +137,7 @@ export class SentrySharedService {
148
137
  message,
149
138
  })
150
139
 
151
- this.sentry().captureException(
152
- _anyToError(
153
- args.length === 1 ? args[0] : args,
154
- Error,
155
- {},
156
- {
157
- stringifyFn: inspectAnyStringifyFn,
158
- },
159
- ),
160
- )
140
+ this.sentry().captureException(_anyToError(args.length === 1 ? args[0] : args))
161
141
  },
162
142
  }
163
143
  }
@@ -7,7 +7,6 @@ import {
7
7
  HttpErrorData,
8
8
  HttpErrorResponse,
9
9
  } from '@naturalcycles/js-lib'
10
- import { inspectAnyStringifyFn } from '@naturalcycles/nodejs-lib'
11
10
  import { SentrySharedService } from '../sentry/sentry.shared.service'
12
11
  import { BackendErrorRequestHandler, BackendRequest, BackendResponse } from './server.model'
13
12
 
@@ -73,14 +72,7 @@ export function respondWithError(req: BackendRequest, res: BackendResponse, err:
73
72
  req.error(err)
74
73
  }
75
74
 
76
- const originalError = _anyToError(
77
- err,
78
- Error,
79
- {},
80
- {
81
- stringifyFn: inspectAnyStringifyFn,
82
- },
83
- )
75
+ const originalError = _anyToError(err)
84
76
 
85
77
  let errorId: string | undefined
86
78
 
@@ -90,7 +82,8 @@ export function respondWithError(req: BackendRequest, res: BackendResponse, err:
90
82
 
91
83
  if (res.headersSent) return
92
84
 
93
- const httpError = _errorToErrorObject<HttpErrorData>(originalError, includeErrorStack)
85
+ const httpError = _errorToErrorObject<HttpErrorData>(originalError)
86
+ if (!includeErrorStack) delete httpError.stack
94
87
 
95
88
  httpError.data.errorId = errorId
96
89
  httpError.data.httpStatusCode ||= 500 // default to 500