@plyaz/types 1.21.4 → 1.22.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/dist/core/init/types.d.ts +22 -1
- package/dist/errors/middleware.d.ts +28 -7
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ import type { ApiClientOptions } from '../../api';
|
|
|
8
8
|
import type { StoreKey } from '../../store';
|
|
9
9
|
import type { FeatureFlagValue, FeatureFlagPollingConfig } from '../../features';
|
|
10
10
|
import type { PackageErrorLike } from '../../errors';
|
|
11
|
-
import type { GlobalErrorHandlerConfig } from '../../errors/middleware';
|
|
11
|
+
import type { GlobalErrorHandlerConfig, ErrorHandlerLogger } from '../../errors/middleware';
|
|
12
12
|
import type { CoreAppEnvironment, CoreAppContext, CoreRuntimeEnvironment } from '../modules';
|
|
13
13
|
import type { CoreDbServiceConfig } from '../services';
|
|
14
14
|
/**
|
|
@@ -299,6 +299,27 @@ export interface CoreErrorHandlerInitConfig extends Omit<GlobalErrorHandlerConfi
|
|
|
299
299
|
* Set to false to use your own error handling.
|
|
300
300
|
*/
|
|
301
301
|
enabled?: boolean;
|
|
302
|
+
/**
|
|
303
|
+
* Whether to auto-create HTTP error handler based on runtime (default: true).
|
|
304
|
+
* When enabled, Core will create the appropriate middleware for:
|
|
305
|
+
* - Express: createHttpErrorHandler
|
|
306
|
+
* - NestJS: createNestJsExceptionFilter
|
|
307
|
+
* - Next.js: withErrorHandler / createNextApiErrorHandler
|
|
308
|
+
* - Node.js: handleNodeError
|
|
309
|
+
*
|
|
310
|
+
* Access via Core.httpErrorHandler or Core.getHttpErrorHandler()
|
|
311
|
+
*/
|
|
312
|
+
httpHandler?: boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Include stack traces in HTTP error responses (default: false in production)
|
|
315
|
+
*/
|
|
316
|
+
includeStack?: boolean;
|
|
317
|
+
/**
|
|
318
|
+
* Custom logger for error handlers.
|
|
319
|
+
* If not provided, uses default console logger.
|
|
320
|
+
* Set to false to disable logging.
|
|
321
|
+
*/
|
|
322
|
+
logger?: ErrorHandlerLogger | boolean;
|
|
302
323
|
}
|
|
303
324
|
/**
|
|
304
325
|
* Base core initialization options
|
|
@@ -7,12 +7,29 @@
|
|
|
7
7
|
import type { Request, Response } from 'express';
|
|
8
8
|
import type { SerializedError, ErrorStoreActions } from './store';
|
|
9
9
|
import type { ErrorEventFactory, ErrorResponse } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Source identifier for error tracking.
|
|
12
|
+
* Used to identify where an error originated from.
|
|
13
|
+
*/
|
|
14
|
+
export type ErrorSource = 'express' | 'nestjs' | 'nodejs' | 'nextjs' | 'http' | 'api' | 'global' | string;
|
|
15
|
+
/**
|
|
16
|
+
* Logger interface for error handlers.
|
|
17
|
+
* Compatible with @plyaz/logger PackageLogger and standard loggers.
|
|
18
|
+
*/
|
|
19
|
+
export interface ErrorHandlerLogger {
|
|
20
|
+
error(message: string, meta?: Record<string, unknown>, ...details: unknown[]): void;
|
|
21
|
+
warn?(message: string, meta?: Record<string, unknown>, ...details: unknown[]): void;
|
|
22
|
+
info?(message: string, meta?: Record<string, unknown>, ...details: unknown[]): void;
|
|
23
|
+
debug?(message: string, meta?: Record<string, unknown>, ...details: unknown[]): void;
|
|
24
|
+
}
|
|
10
25
|
/**
|
|
11
26
|
* Configuration for HTTP error handler middleware.
|
|
12
|
-
* Used by Express and
|
|
27
|
+
* Used by Express, NestJS, and other Node.js backend error handlers.
|
|
13
28
|
*/
|
|
14
29
|
export interface HttpErrorHandlerConfig {
|
|
15
|
-
/**
|
|
30
|
+
/** Source identifier for errors (e.g., 'express', 'nestjs', 'nextjs') */
|
|
31
|
+
source?: ErrorSource;
|
|
32
|
+
/** Global error handler instance (optional - for tracking). If not provided, uses global handler. */
|
|
16
33
|
errorHandler?: GlobalErrorHandler;
|
|
17
34
|
/** Include stack traces in response (default: false) */
|
|
18
35
|
includeStack?: boolean;
|
|
@@ -20,8 +37,10 @@ export interface HttpErrorHandlerConfig {
|
|
|
20
37
|
formatError?: (error: SerializedError, req: Request) => ErrorResponse;
|
|
21
38
|
/** Callback when error is handled */
|
|
22
39
|
onError?: (error: SerializedError, req: Request, res: Response) => void;
|
|
23
|
-
/** Log errors
|
|
24
|
-
logErrors?: boolean;
|
|
40
|
+
/** Log errors (default: true). Set false to disable, or provide a logger instance */
|
|
41
|
+
logErrors?: boolean | ErrorHandlerLogger;
|
|
42
|
+
/** Callback before clearing errors - use for monitoring (Grafana, Sentry, Datadog) */
|
|
43
|
+
beforeClear?: (errors: SerializedError[]) => void | Promise<void>;
|
|
25
44
|
}
|
|
26
45
|
/**
|
|
27
46
|
* Configuration for the global error handler.
|
|
@@ -46,10 +65,12 @@ export interface GlobalErrorHandlerConfig {
|
|
|
46
65
|
* Provides methods to capture errors and manage the error store.
|
|
47
66
|
*/
|
|
48
67
|
export interface GlobalErrorHandler {
|
|
49
|
-
/** Manually capture an error */
|
|
68
|
+
/** Manually capture an error (supports single error or array of errors) */
|
|
50
69
|
captureError: (error: unknown, source?: string) => void;
|
|
51
|
-
/** Manually capture an exception (alias) */
|
|
70
|
+
/** Manually capture an exception (alias for captureError) */
|
|
52
71
|
captureException: (error: unknown, source?: string) => void;
|
|
72
|
+
/** Capture multiple errors at once (batch operation) */
|
|
73
|
+
captureErrors: (errors: unknown[], source?: string) => void;
|
|
53
74
|
/** Get the error store */
|
|
54
75
|
getStore: () => ErrorStoreActions;
|
|
55
76
|
/** Cleanup and remove listeners */
|
|
@@ -86,7 +107,7 @@ export interface BackendErrorStore extends ErrorStoreActions {
|
|
|
86
107
|
/**
|
|
87
108
|
* Keys for backend error store action methods.
|
|
88
109
|
*/
|
|
89
|
-
export type BackendErrorStoreActionKeys = 'addError' | 'removeError' | 'clearErrors' | 'clearErrorsByCategory' | 'clearErrorsBySource' | 'dismissError' | 'dismissAllErrors' | 'setConnected' | 'reset';
|
|
110
|
+
export type BackendErrorStoreActionKeys = 'addError' | 'addErrors' | 'removeError' | 'clearErrors' | 'clearErrorsByCategory' | 'clearErrorsBySource' | 'dismissError' | 'dismissAllErrors' | 'setConnected' | 'reset';
|
|
90
111
|
/**
|
|
91
112
|
* Keys for backend error store getter methods.
|
|
92
113
|
*/
|
package/package.json
CHANGED