@naturalcycles/backend-lib 9.67.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
|
-
|
|
29
|
-
|
|
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
|
@@ -37,10 +37,11 @@ export function getRequest(): BackendRequest | undefined {
|
|
|
37
37
|
* @experimental
|
|
38
38
|
*/
|
|
39
39
|
export function getRequestLogger(): CommonLogger {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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,
|