@naturalcycles/backend-lib 4.13.0 → 4.14.1

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/cfg/tsconfig.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "compilerOptions": {
8
8
  // Target/module
9
9
  "target": "es2021",
10
- "lib": ["es2021"], // add "dom" if needed
10
+ "lib": ["esnext"], // add "dom" if needed
11
11
  "module": "commonjs",
12
12
  "moduleResolution": "node",
13
13
 
@@ -86,9 +86,7 @@ class SentrySharedService {
86
86
  }),
87
87
  // data: (err as AppError).data, // included in message
88
88
  });
89
- return this.sentry().captureException((0, js_lib_1._anyToError)(err, Error, {}, {
90
- stringifyFn: nodejs_lib_1.inspectAnyStringifyFn,
91
- }));
89
+ return this.sentry().captureException((0, js_lib_1._anyToError)(err));
92
90
  }
93
91
  /**
94
92
  * Returns "eventId"
@@ -121,9 +119,7 @@ class SentrySharedService {
121
119
  this.sentry().addBreadcrumb({
122
120
  message,
123
121
  });
124
- this.sentry().captureException((0, js_lib_1._anyToError)(args.length === 1 ? args[0] : args, Error, {}, {
125
- stringifyFn: nodejs_lib_1.inspectAnyStringifyFn,
126
- }));
122
+ this.sentry().captureException((0, js_lib_1._anyToError)(args.length === 1 ? args[0] : args));
127
123
  },
128
124
  };
129
125
  }
@@ -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.13.0",
3
+ "version": "4.14.1",
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'
@@ -99,16 +99,7 @@ export class SentrySharedService {
99
99
  // data: (err as AppError).data, // included in message
100
100
  })
101
101
 
102
- return this.sentry().captureException(
103
- _anyToError(
104
- err,
105
- Error,
106
- {},
107
- {
108
- stringifyFn: inspectAnyStringifyFn,
109
- },
110
- ),
111
- )
102
+ return this.sentry().captureException(_anyToError(err))
112
103
  }
113
104
 
114
105
  /**
@@ -148,16 +139,7 @@ export class SentrySharedService {
148
139
  message,
149
140
  })
150
141
 
151
- this.sentry().captureException(
152
- _anyToError(
153
- args.length === 1 ? args[0] : args,
154
- Error,
155
- {},
156
- {
157
- stringifyFn: inspectAnyStringifyFn,
158
- },
159
- ),
160
- )
142
+ this.sentry().captureException(_anyToError(args.length === 1 ? args[0] : args))
161
143
  },
162
144
  }
163
145
  }
@@ -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