@naturalcycles/backend-lib 4.18.0 → 4.18.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.
@@ -91,7 +91,7 @@ async function deployHealthCheck(url, opt = {}) {
91
91
  const started = Date.now();
92
92
  const { err, statusCode = 0 } = await fetcher.doFetch({
93
93
  url,
94
- mode: 'json',
94
+ responseType: 'json',
95
95
  timeoutSeconds: timeoutSec,
96
96
  retry: {
97
97
  count: 0,
@@ -26,10 +26,10 @@ export declare class SentrySharedService {
26
26
  */
27
27
  setUserId(id: string): void;
28
28
  /**
29
- * Does console.error(err)
29
+ * Does console.log(err)
30
30
  * Returns "eventId" or undefined (if error was not reported).
31
31
  */
32
- captureException(err: any, logError?: boolean): string | undefined;
32
+ captureException(err_: any, logError?: boolean): string | undefined;
33
33
  /**
34
34
  * Returns "eventId"
35
35
  */
@@ -63,20 +63,23 @@ class SentrySharedService {
63
63
  });
64
64
  }
65
65
  /**
66
- * Does console.error(err)
66
+ * Does console.log(err)
67
67
  * Returns "eventId" or undefined (if error was not reported).
68
68
  */
69
- captureException(err, logError = true) {
70
- // console.error(err)
69
+ captureException(err_, logError = true) {
70
+ // normalize the error
71
+ const err = (0, js_lib_1._anyToError)(err_);
72
+ const data = err instanceof js_lib_1.AppError ? err.data : undefined;
71
73
  // Using request-aware logger here
72
74
  if (logError) {
73
- (0, index_1.getRequestLogger)().error('captureException:', err);
75
+ // Log both the error and attached ErrorData (if any)
76
+ (0, index_1.getRequestLogger)().error('captureException:', ...[err_, data].filter(Boolean));
74
77
  }
75
- if (err?.data?.report === false) {
78
+ if (data?.report === false) {
76
79
  // Skip reporting the error
77
80
  return;
78
81
  }
79
- if (err?.data?.reportRate) {
82
+ if (data?.reportRate) {
80
83
  const reportRate = err.data.reportRate;
81
84
  // E.g rate of 0.1 means 10% of errors are reported
82
85
  if (Math.random() > reportRate)
@@ -89,9 +92,8 @@ class SentrySharedService {
89
92
  message: (0, nodejs_lib_1.inspectAny)(err, {
90
93
  colors: false,
91
94
  }),
92
- // data: (err as AppError).data, // included in message
93
95
  });
94
- return this.sentry().captureException((0, js_lib_1._anyToError)(err));
96
+ return this.sentry().captureException(err);
95
97
  }
96
98
  /**
97
99
  * Returns "eventId"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
- "version": "4.18.0",
3
+ "version": "4.18.2",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "serve": "APP_ENV=dev nodemon",
@@ -135,7 +135,7 @@ export async function deployHealthCheck(
135
135
 
136
136
  const { err, statusCode = 0 } = await fetcher.doFetch({
137
137
  url,
138
- mode: 'json',
138
+ responseType: 'json',
139
139
  timeoutSeconds: timeoutSec,
140
140
  retry: {
141
141
  count: 0,
@@ -1,4 +1,11 @@
1
- import { _anyToError, _Memo, AppError, CommonLogger, CommonLogLevel } from '@naturalcycles/js-lib'
1
+ import {
2
+ _anyToError,
3
+ _Memo,
4
+ AppError,
5
+ CommonLogger,
6
+ CommonLogLevel,
7
+ ErrorData,
8
+ } from '@naturalcycles/js-lib'
2
9
  import { inspectAny } from '@naturalcycles/nodejs-lib'
3
10
  import type { Breadcrumb, NodeOptions, SeverityLevel } from '@sentry/node'
4
11
  import type * as SentryLib from '@sentry/node'
@@ -73,22 +80,26 @@ export class SentrySharedService {
73
80
  }
74
81
 
75
82
  /**
76
- * Does console.error(err)
83
+ * Does console.log(err)
77
84
  * Returns "eventId" or undefined (if error was not reported).
78
85
  */
79
- captureException(err: any, logError = true): string | undefined {
80
- // console.error(err)
86
+ captureException(err_: any, logError = true): string | undefined {
87
+ // normalize the error
88
+ const err = _anyToError(err_)
89
+ const data = err instanceof AppError ? (err.data as ErrorData) : undefined
90
+
81
91
  // Using request-aware logger here
82
92
  if (logError) {
83
- getRequestLogger().error('captureException:', err)
93
+ // Log both the error and attached ErrorData (if any)
94
+ getRequestLogger().error('captureException:', ...[err_, data].filter(Boolean))
84
95
  }
85
96
 
86
- if (err?.data?.report === false) {
97
+ if (data?.report === false) {
87
98
  // Skip reporting the error
88
99
  return
89
100
  }
90
101
 
91
- if (err?.data?.reportRate) {
102
+ if (data?.reportRate) {
92
103
  const reportRate = (err as AppError).data.reportRate!
93
104
  // E.g rate of 0.1 means 10% of errors are reported
94
105
  if (Math.random() > reportRate) return
@@ -101,10 +112,9 @@ export class SentrySharedService {
101
112
  message: inspectAny(err, {
102
113
  colors: false,
103
114
  }),
104
- // data: (err as AppError).data, // included in message
105
115
  })
106
116
 
107
- return this.sentry().captureException(_anyToError(err))
117
+ return this.sentry().captureException(err)
108
118
  }
109
119
 
110
120
  /**