@naturalcycles/backend-lib 9.66.0 → 9.68.0

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.
@@ -25,8 +25,14 @@ export function getRequest() {
25
25
  * @experimental
26
26
  */
27
27
  export function getRequestLogger() {
28
- return (storage().getStore()?.req ||
29
- (isGAE || isCloudRun ? gcpStructuredLogger : isCI ? ciLogger : devLogger));
28
+ const req = storage().getStore()?.req;
29
+ if (req)
30
+ return req;
31
+ if (isGAE || isCloudRun)
32
+ return gcpStructuredLogger;
33
+ if (isCI)
34
+ return ciLogger;
35
+ return devLogger;
30
36
  }
31
37
  /**
32
38
  * CommonLogger implementation that is Request-bound.
@@ -6,7 +6,7 @@ export interface GenericErrorMiddlewareCfg {
6
6
  * Generic hook that can be used to **mutate** errors before they are returned to client.
7
7
  * This function does not affect data sent to sentry.
8
8
  */
9
- formatError?: (err: ErrorObject) => void;
9
+ formatError?: (err: ErrorObject, req: BackendRequest) => void;
10
10
  }
11
11
  export interface ErrorReportingService {
12
12
  /**
@@ -58,7 +58,7 @@ export function respondWithError(req, res, err) {
58
58
  errorId,
59
59
  headersSent: headersSent || undefined,
60
60
  });
61
- formatError?.(httpError); // Mutates
61
+ formatError?.(httpError, req); // Mutates the error
62
62
  res.status(httpError.data.backendResponseStatusCode).json({
63
63
  error: httpError,
64
64
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.66.0",
4
+ "version": "9.68.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/db-lib": "^10",
7
7
  "@naturalcycles/js-lib": "^15",
@@ -43,11 +43,11 @@
43
43
  }
44
44
  },
45
45
  "devDependencies": {
46
+ "@naturalcycles/dev-lib": "0.0.0",
46
47
  "@sentry/node-core": "^10",
47
48
  "@types/busboy": "^1",
48
49
  "typescript": "^7",
49
- "fastify": "^5",
50
- "@naturalcycles/dev-lib": "0.0.0"
50
+ "fastify": "^5"
51
51
  },
52
52
  "exports": {
53
53
  ".": "./dist/index.js",
@@ -37,10 +37,11 @@ export function getRequest(): BackendRequest | undefined {
37
37
  * @experimental
38
38
  */
39
39
  export function getRequestLogger(): CommonLogger {
40
- return (
41
- storage().getStore()?.req ||
42
- (isGAE || isCloudRun ? gcpStructuredLogger : isCI ? ciLogger : devLogger)
43
- )
40
+ const req = storage().getStore()?.req
41
+ if (req) return req
42
+ if (isGAE || isCloudRun) return gcpStructuredLogger
43
+ if (isCI) return ciLogger
44
+ return devLogger
44
45
  }
45
46
 
46
47
  /**
@@ -10,7 +10,7 @@ export interface GenericErrorMiddlewareCfg {
10
10
  * Generic hook that can be used to **mutate** errors before they are returned to client.
11
11
  * This function does not affect data sent to sentry.
12
12
  */
13
- formatError?: (err: ErrorObject) => void
13
+ formatError?: (err: ErrorObject, req: BackendRequest) => void
14
14
  }
15
15
 
16
16
  export interface ErrorReportingService {
@@ -95,7 +95,7 @@ export function respondWithError(req: BackendRequest, res: BackendResponse, err:
95
95
  headersSent: headersSent || undefined,
96
96
  })
97
97
 
98
- formatError?.(httpError) // Mutates
98
+ formatError?.(httpError, req) // Mutates the error
99
99
 
100
100
  res.status(httpError.data.backendResponseStatusCode).json({
101
101
  error: httpError,