@cyanheads/pubchem-mcp-server 1.0.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/LICENSE +201 -0
- package/README.md +236 -0
- package/dist/config/index.d.ts +98 -0
- package/dist/config/index.js +326 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +214 -0
- package/dist/mcp-server/server.d.ts +21 -0
- package/dist/mcp-server/server.js +124 -0
- package/dist/mcp-server/tools/fetchAssaySummary/index.d.ts +7 -0
- package/dist/mcp-server/tools/fetchAssaySummary/index.js +7 -0
- package/dist/mcp-server/tools/fetchAssaySummary/logic.d.ts +71 -0
- package/dist/mcp-server/tools/fetchAssaySummary/logic.js +96 -0
- package/dist/mcp-server/tools/fetchAssaySummary/registration.d.ts +12 -0
- package/dist/mcp-server/tools/fetchAssaySummary/registration.js +68 -0
- package/dist/mcp-server/tools/fetchCompoundProperties/index.d.ts +7 -0
- package/dist/mcp-server/tools/fetchCompoundProperties/index.js +7 -0
- package/dist/mcp-server/tools/fetchCompoundProperties/logic.d.ts +131 -0
- package/dist/mcp-server/tools/fetchCompoundProperties/logic.js +100 -0
- package/dist/mcp-server/tools/fetchCompoundProperties/registration.d.ts +13 -0
- package/dist/mcp-server/tools/fetchCompoundProperties/registration.js +52 -0
- package/dist/mcp-server/tools/fetchCompoundXrefs/index.d.ts +7 -0
- package/dist/mcp-server/tools/fetchCompoundXrefs/index.js +7 -0
- package/dist/mcp-server/tools/fetchCompoundXrefs/logic.d.ts +89 -0
- package/dist/mcp-server/tools/fetchCompoundXrefs/logic.js +145 -0
- package/dist/mcp-server/tools/fetchCompoundXrefs/registration.d.ts +13 -0
- package/dist/mcp-server/tools/fetchCompoundXrefs/registration.js +52 -0
- package/dist/mcp-server/tools/fetchSubstanceDetails/index.d.ts +7 -0
- package/dist/mcp-server/tools/fetchSubstanceDetails/index.js +7 -0
- package/dist/mcp-server/tools/fetchSubstanceDetails/logic.d.ts +69 -0
- package/dist/mcp-server/tools/fetchSubstanceDetails/logic.js +97 -0
- package/dist/mcp-server/tools/fetchSubstanceDetails/registration.d.ts +13 -0
- package/dist/mcp-server/tools/fetchSubstanceDetails/registration.js +79 -0
- package/dist/mcp-server/tools/getCompoundImage/index.d.ts +7 -0
- package/dist/mcp-server/tools/getCompoundImage/index.js +7 -0
- package/dist/mcp-server/tools/getCompoundImage/logic.d.ts +42 -0
- package/dist/mcp-server/tools/getCompoundImage/logic.js +68 -0
- package/dist/mcp-server/tools/getCompoundImage/registration.d.ts +12 -0
- package/dist/mcp-server/tools/getCompoundImage/registration.js +57 -0
- package/dist/mcp-server/tools/searchAssaysByTarget/index.d.ts +7 -0
- package/dist/mcp-server/tools/searchAssaysByTarget/index.js +7 -0
- package/dist/mcp-server/tools/searchAssaysByTarget/logic.d.ts +35 -0
- package/dist/mcp-server/tools/searchAssaysByTarget/logic.js +64 -0
- package/dist/mcp-server/tools/searchAssaysByTarget/registration.d.ts +12 -0
- package/dist/mcp-server/tools/searchAssaysByTarget/registration.js +62 -0
- package/dist/mcp-server/tools/searchCompoundByIdentifier/index.d.ts +7 -0
- package/dist/mcp-server/tools/searchCompoundByIdentifier/index.js +7 -0
- package/dist/mcp-server/tools/searchCompoundByIdentifier/logic.d.ts +35 -0
- package/dist/mcp-server/tools/searchCompoundByIdentifier/logic.js +59 -0
- package/dist/mcp-server/tools/searchCompoundByIdentifier/registration.d.ts +12 -0
- package/dist/mcp-server/tools/searchCompoundByIdentifier/registration.js +51 -0
- package/dist/mcp-server/tools/searchCompoundsByFormula/index.d.ts +7 -0
- package/dist/mcp-server/tools/searchCompoundsByFormula/index.js +7 -0
- package/dist/mcp-server/tools/searchCompoundsByFormula/logic.d.ts +38 -0
- package/dist/mcp-server/tools/searchCompoundsByFormula/logic.js +75 -0
- package/dist/mcp-server/tools/searchCompoundsByFormula/registration.d.ts +12 -0
- package/dist/mcp-server/tools/searchCompoundsByFormula/registration.js +62 -0
- package/dist/mcp-server/tools/searchCompoundsBySimilarity/index.d.ts +7 -0
- package/dist/mcp-server/tools/searchCompoundsBySimilarity/index.js +7 -0
- package/dist/mcp-server/tools/searchCompoundsBySimilarity/logic.d.ts +41 -0
- package/dist/mcp-server/tools/searchCompoundsBySimilarity/logic.js +82 -0
- package/dist/mcp-server/tools/searchCompoundsBySimilarity/registration.d.ts +12 -0
- package/dist/mcp-server/tools/searchCompoundsBySimilarity/registration.js +62 -0
- package/dist/mcp-server/tools/searchCompoundsByStructure/index.d.ts +7 -0
- package/dist/mcp-server/tools/searchCompoundsByStructure/index.js +7 -0
- package/dist/mcp-server/tools/searchCompoundsByStructure/logic.d.ts +41 -0
- package/dist/mcp-server/tools/searchCompoundsByStructure/logic.js +78 -0
- package/dist/mcp-server/tools/searchCompoundsByStructure/registration.d.ts +13 -0
- package/dist/mcp-server/tools/searchCompoundsByStructure/registration.js +63 -0
- package/dist/mcp-server/transports/auth/core/authContext.d.ts +33 -0
- package/dist/mcp-server/transports/auth/core/authContext.js +24 -0
- package/dist/mcp-server/transports/auth/core/authTypes.d.ts +17 -0
- package/dist/mcp-server/transports/auth/core/authTypes.js +5 -0
- package/dist/mcp-server/transports/auth/core/authUtils.d.ts +18 -0
- package/dist/mcp-server/transports/auth/core/authUtils.js +45 -0
- package/dist/mcp-server/transports/auth/index.d.ts +10 -0
- package/dist/mcp-server/transports/auth/index.js +9 -0
- package/dist/mcp-server/transports/auth/strategies/jwt/jwtMiddleware.d.ts +27 -0
- package/dist/mcp-server/transports/auth/strategies/jwt/jwtMiddleware.js +149 -0
- package/dist/mcp-server/transports/auth/strategies/oauth/oauthMiddleware.d.ts +20 -0
- package/dist/mcp-server/transports/auth/strategies/oauth/oauthMiddleware.js +124 -0
- package/dist/mcp-server/transports/httpErrorHandler.d.ts +26 -0
- package/dist/mcp-server/transports/httpErrorHandler.js +73 -0
- package/dist/mcp-server/transports/httpTransport.d.ts +21 -0
- package/dist/mcp-server/transports/httpTransport.js +208 -0
- package/dist/mcp-server/transports/stdioTransport.d.ts +42 -0
- package/dist/mcp-server/transports/stdioTransport.js +63 -0
- package/dist/services/pubchem/pubchemApiClient.d.ts +52 -0
- package/dist/services/pubchem/pubchemApiClient.js +120 -0
- package/dist/types-global/errors.d.ts +127 -0
- package/dist/types-global/errors.js +126 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/internal/errorHandler.d.ts +176 -0
- package/dist/utils/internal/errorHandler.js +335 -0
- package/dist/utils/internal/index.d.ts +9 -0
- package/dist/utils/internal/index.js +9 -0
- package/dist/utils/internal/logger.d.ts +148 -0
- package/dist/utils/internal/logger.js +430 -0
- package/dist/utils/internal/requestContext.d.ts +83 -0
- package/dist/utils/internal/requestContext.js +72 -0
- package/dist/utils/metrics/index.d.ts +7 -0
- package/dist/utils/metrics/index.js +7 -0
- package/dist/utils/metrics/tokenCounter.d.ts +35 -0
- package/dist/utils/metrics/tokenCounter.js +110 -0
- package/dist/utils/network/fetchWithTimeout.d.ts +21 -0
- package/dist/utils/network/fetchWithTimeout.js +59 -0
- package/dist/utils/network/index.d.ts +6 -0
- package/dist/utils/network/index.js +5 -0
- package/dist/utils/parsing/dateParser.d.ts +73 -0
- package/dist/utils/parsing/dateParser.js +107 -0
- package/dist/utils/parsing/index.d.ts +8 -0
- package/dist/utils/parsing/index.js +8 -0
- package/dist/utils/parsing/jsonParser.d.ts +82 -0
- package/dist/utils/parsing/jsonParser.js +126 -0
- package/dist/utils/scheduling/index.d.ts +6 -0
- package/dist/utils/scheduling/index.js +6 -0
- package/dist/utils/scheduling/scheduler.d.ts +72 -0
- package/dist/utils/scheduling/scheduler.js +152 -0
- package/dist/utils/security/idGenerator.d.ts +137 -0
- package/dist/utils/security/idGenerator.js +215 -0
- package/dist/utils/security/index.d.ts +9 -0
- package/dist/utils/security/index.js +9 -0
- package/dist/utils/security/rateLimiter.d.ts +108 -0
- package/dist/utils/security/rateLimiter.js +179 -0
- package/dist/utils/security/sanitization.d.ts +184 -0
- package/dist/utils/security/sanitization.js +453 -0
- package/package.json +108 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Defines standardized error codes, a custom error class, and related schemas
|
|
3
|
+
* for handling errors within the Model Context Protocol (MCP) server and its components.
|
|
4
|
+
* This module provides a structured way to represent and communicate errors, ensuring
|
|
5
|
+
* consistency and clarity for both server-side operations and client-side error handling.
|
|
6
|
+
* @module src/types-global/errors
|
|
7
|
+
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
/**
|
|
10
|
+
* Defines a comprehensive set of standardized error codes for common issues encountered
|
|
11
|
+
* within MCP servers, tools, or related operations. These codes are designed to help
|
|
12
|
+
* clients and developers programmatically understand the nature of an error, facilitating
|
|
13
|
+
* more precise error handling and debugging.
|
|
14
|
+
*/
|
|
15
|
+
export var BaseErrorCode;
|
|
16
|
+
(function (BaseErrorCode) {
|
|
17
|
+
/** Access denied due to invalid credentials or lack of authentication. */
|
|
18
|
+
BaseErrorCode["UNAUTHORIZED"] = "UNAUTHORIZED";
|
|
19
|
+
/** Access denied despite valid authentication, due to insufficient permissions. */
|
|
20
|
+
BaseErrorCode["FORBIDDEN"] = "FORBIDDEN";
|
|
21
|
+
/** The requested resource or entity could not be found. */
|
|
22
|
+
BaseErrorCode["NOT_FOUND"] = "NOT_FOUND";
|
|
23
|
+
/** The request could not be completed due to a conflict with the current state of the resource. */
|
|
24
|
+
BaseErrorCode["CONFLICT"] = "CONFLICT";
|
|
25
|
+
/** The request failed due to invalid input parameters or data. */
|
|
26
|
+
BaseErrorCode["VALIDATION_ERROR"] = "VALIDATION_ERROR";
|
|
27
|
+
/** The request was made with an invalid input. */
|
|
28
|
+
BaseErrorCode["INVALID_INPUT"] = "INVALID_INPUT";
|
|
29
|
+
/** The request was made with a method that is not allowed for the resource. */
|
|
30
|
+
BaseErrorCode["METHOD_NOT_ALLOWED"] = "METHOD_NOT_ALLOWED";
|
|
31
|
+
/** An error occurred while parsing input data (e.g., date string, JSON). */
|
|
32
|
+
BaseErrorCode["PARSING_ERROR"] = "PARSING_ERROR";
|
|
33
|
+
/** The request was rejected because the client has exceeded rate limits. */
|
|
34
|
+
BaseErrorCode["RATE_LIMITED"] = "RATE_LIMITED";
|
|
35
|
+
/** The request timed out before a response could be generated. */
|
|
36
|
+
BaseErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
37
|
+
/** The service is temporarily unavailable, possibly due to maintenance or overload. */
|
|
38
|
+
BaseErrorCode["SERVICE_UNAVAILABLE"] = "SERVICE_UNAVAILABLE";
|
|
39
|
+
/** The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server. */
|
|
40
|
+
BaseErrorCode["GATEWAY_TIMEOUT"] = "GATEWAY_TIMEOUT";
|
|
41
|
+
/** A generic error occurred when interacting with an external service. */
|
|
42
|
+
BaseErrorCode["EXTERNAL_SERVICE_ERROR"] = "EXTERNAL_SERVICE_ERROR";
|
|
43
|
+
/** An unexpected error occurred on the server side. */
|
|
44
|
+
BaseErrorCode["INTERNAL_ERROR"] = "INTERNAL_ERROR";
|
|
45
|
+
/** An error occurred, but the specific cause is unknown or cannot be categorized. */
|
|
46
|
+
BaseErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
47
|
+
/** An error occurred during the loading or validation of configuration data. */
|
|
48
|
+
BaseErrorCode["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
|
|
49
|
+
/** An error occurred during the initialization phase of a service or module. */
|
|
50
|
+
BaseErrorCode["INITIALIZATION_FAILED"] = "INITIALIZATION_FAILED";
|
|
51
|
+
/** A service was used before it was properly initialized. */
|
|
52
|
+
BaseErrorCode["SERVICE_NOT_INITIALIZED"] = "SERVICE_NOT_INITIALIZED";
|
|
53
|
+
/** A generic error occurred during a database operation. */
|
|
54
|
+
BaseErrorCode["DATABASE_ERROR"] = "DATABASE_ERROR";
|
|
55
|
+
/** An error occurred while loading or interacting with an extension. */
|
|
56
|
+
BaseErrorCode["EXTENSION_ERROR"] = "EXTENSION_ERROR";
|
|
57
|
+
/** An error occurred during the shutdown phase of a service or module. */
|
|
58
|
+
BaseErrorCode["SHUTDOWN_ERROR"] = "SHUTDOWN_ERROR";
|
|
59
|
+
/** A generic error occurred during the execution of an agent's task. */
|
|
60
|
+
BaseErrorCode["AGENT_EXECUTION_ERROR"] = "AGENT_EXECUTION_ERROR";
|
|
61
|
+
})(BaseErrorCode || (BaseErrorCode = {}));
|
|
62
|
+
/**
|
|
63
|
+
* Custom error class for MCP-specific errors, extending the built-in `Error` class.
|
|
64
|
+
* It standardizes error reporting by encapsulating a `BaseErrorCode`, a descriptive
|
|
65
|
+
* human-readable message, and optional structured details for more context.
|
|
66
|
+
*
|
|
67
|
+
* This class is central to error handling within the MCP framework, allowing for
|
|
68
|
+
* consistent error creation and propagation.
|
|
69
|
+
*/
|
|
70
|
+
export class McpError extends Error {
|
|
71
|
+
/**
|
|
72
|
+
* Creates an instance of McpError.
|
|
73
|
+
*
|
|
74
|
+
* @param code - The standardized error code that categorizes the error.
|
|
75
|
+
* @param message - A human-readable description of the error.
|
|
76
|
+
* @param details - Optional. A record containing additional structured details about the error.
|
|
77
|
+
*/
|
|
78
|
+
constructor(code, message, details) {
|
|
79
|
+
super(message);
|
|
80
|
+
this.code = code;
|
|
81
|
+
this.details = details;
|
|
82
|
+
this.name = "McpError";
|
|
83
|
+
// Maintain a proper prototype chain.
|
|
84
|
+
Object.setPrototypeOf(this, McpError.prototype);
|
|
85
|
+
// Capture the stack trace, excluding the constructor call from it, if available.
|
|
86
|
+
if (Error.captureStackTrace) {
|
|
87
|
+
Error.captureStackTrace(this, McpError);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Zod schema for validating error objects. This schema can be used for:
|
|
93
|
+
* - Validating error structures when parsing error responses from external services.
|
|
94
|
+
* - Ensuring consistency when creating or handling error objects internally.
|
|
95
|
+
* - Generating TypeScript types for error objects.
|
|
96
|
+
*
|
|
97
|
+
* The schema enforces the presence of a `code` (from {@link BaseErrorCode}) and a `message`,
|
|
98
|
+
* and allows for optional `details`.
|
|
99
|
+
*/
|
|
100
|
+
export const ErrorSchema = z
|
|
101
|
+
.object({
|
|
102
|
+
/**
|
|
103
|
+
* The error code, corresponding to one of the {@link BaseErrorCode} enum values.
|
|
104
|
+
* This field is required and helps in programmatically identifying the error type.
|
|
105
|
+
*/
|
|
106
|
+
code: z
|
|
107
|
+
.nativeEnum(BaseErrorCode)
|
|
108
|
+
.describe("Standardized error code from BaseErrorCode enum"),
|
|
109
|
+
/**
|
|
110
|
+
* A human-readable, descriptive message explaining the error.
|
|
111
|
+
* This field is required and provides context to developers or users.
|
|
112
|
+
*/
|
|
113
|
+
message: z
|
|
114
|
+
.string()
|
|
115
|
+
.min(1, "Error message cannot be empty.")
|
|
116
|
+
.describe("Detailed human-readable error message"),
|
|
117
|
+
/**
|
|
118
|
+
* Optional. A record containing additional structured details or context about the error.
|
|
119
|
+
* This can include things like invalid field names, specific values that caused issues, or other relevant data.
|
|
120
|
+
*/
|
|
121
|
+
details: z
|
|
122
|
+
.record(z.unknown())
|
|
123
|
+
.optional()
|
|
124
|
+
.describe("Optional structured details providing more context about the error"),
|
|
125
|
+
})
|
|
126
|
+
.describe("Schema for validating structured error objects, ensuring consistency in error reporting.");
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Barrel file for the utils module.
|
|
3
|
+
* This file re-exports all utilities from their categorized subdirectories,
|
|
4
|
+
* providing a single entry point for accessing utility functions.
|
|
5
|
+
* @module src/utils
|
|
6
|
+
*/
|
|
7
|
+
export * from "./internal/index.js";
|
|
8
|
+
export * from "./metrics/index.js";
|
|
9
|
+
export * from "./parsing/index.js";
|
|
10
|
+
export * from "./security/index.js";
|
|
11
|
+
export * from "./network/index.js";
|
|
12
|
+
export * from "./scheduling/index.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Barrel file for the utils module.
|
|
3
|
+
* This file re-exports all utilities from their categorized subdirectories,
|
|
4
|
+
* providing a single entry point for accessing utility functions.
|
|
5
|
+
* @module src/utils
|
|
6
|
+
*/
|
|
7
|
+
// Re-export all utilities from their categorized subdirectories
|
|
8
|
+
export * from "./internal/index.js";
|
|
9
|
+
export * from "./metrics/index.js";
|
|
10
|
+
export * from "./parsing/index.js";
|
|
11
|
+
export * from "./security/index.js";
|
|
12
|
+
export * from "./network/index.js";
|
|
13
|
+
export * from "./scheduling/index.js";
|
|
14
|
+
// It's good practice to have index.ts files in each subdirectory
|
|
15
|
+
// that export the contents of that directory.
|
|
16
|
+
// Assuming those will be created or already exist.
|
|
17
|
+
// If not, this might need adjustment to export specific files, e.g.:
|
|
18
|
+
// export * from './internal/errorHandler.js';
|
|
19
|
+
// export * from './internal/logger.js';
|
|
20
|
+
// ... etc.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview This module provides utilities for robust error handling.
|
|
3
|
+
* It defines structures for error context, options for handling errors,
|
|
4
|
+
* and mappings for classifying errors. The main `ErrorHandler` class
|
|
5
|
+
* offers static methods for consistent error processing, logging, and transformation.
|
|
6
|
+
* @module src/utils/internal/errorHandler
|
|
7
|
+
*/
|
|
8
|
+
import { BaseErrorCode } from "../../types-global/errors.js";
|
|
9
|
+
/**
|
|
10
|
+
* Defines a generic structure for providing context with errors.
|
|
11
|
+
* This context can include identifiers like `requestId` or any other relevant
|
|
12
|
+
* key-value pairs that aid in debugging or understanding the error's circumstances.
|
|
13
|
+
*/
|
|
14
|
+
export interface ErrorContext {
|
|
15
|
+
/**
|
|
16
|
+
* A unique identifier for the request or operation during which the error occurred.
|
|
17
|
+
* Useful for tracing errors through logs and distributed systems.
|
|
18
|
+
*/
|
|
19
|
+
requestId?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Allows for arbitrary additional context information.
|
|
22
|
+
* Keys are strings, and values can be of any type.
|
|
23
|
+
*/
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Configuration options for the `ErrorHandler.handleError` method.
|
|
28
|
+
* These options control how an error is processed, logged, and whether it's rethrown.
|
|
29
|
+
*/
|
|
30
|
+
export interface ErrorHandlerOptions {
|
|
31
|
+
/**
|
|
32
|
+
* The context of the operation that caused the error.
|
|
33
|
+
* This can include `requestId` and other relevant debugging information.
|
|
34
|
+
*/
|
|
35
|
+
context?: ErrorContext;
|
|
36
|
+
/**
|
|
37
|
+
* A descriptive name of the operation being performed when the error occurred.
|
|
38
|
+
* This helps in identifying the source or nature of the error in logs.
|
|
39
|
+
* Example: "UserLogin", "ProcessPayment", "FetchUserProfile".
|
|
40
|
+
*/
|
|
41
|
+
operation: string;
|
|
42
|
+
/**
|
|
43
|
+
* The input data or parameters that were being processed when the error occurred.
|
|
44
|
+
* This input will be sanitized before logging to prevent sensitive data exposure.
|
|
45
|
+
*/
|
|
46
|
+
input?: unknown;
|
|
47
|
+
/**
|
|
48
|
+
* If true, the (potentially transformed) error will be rethrown after handling.
|
|
49
|
+
* Defaults to `false`.
|
|
50
|
+
*/
|
|
51
|
+
rethrow?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* A specific `BaseErrorCode` to assign to the error, overriding any
|
|
54
|
+
* automatically determined error code.
|
|
55
|
+
*/
|
|
56
|
+
errorCode?: BaseErrorCode;
|
|
57
|
+
/**
|
|
58
|
+
* A custom function to map or transform the original error into a new `Error` instance.
|
|
59
|
+
* If provided, this function is used instead of the default `McpError` creation.
|
|
60
|
+
* @param error - The original error that occurred.
|
|
61
|
+
* @returns The transformed error.
|
|
62
|
+
*/
|
|
63
|
+
errorMapper?: (error: unknown) => Error;
|
|
64
|
+
/**
|
|
65
|
+
* If true, stack traces will be included in the logs.
|
|
66
|
+
* Defaults to `true`.
|
|
67
|
+
*/
|
|
68
|
+
includeStack?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* If true, indicates that the error is critical and might require immediate attention
|
|
71
|
+
* or could lead to system instability. This is primarily for logging and alerting.
|
|
72
|
+
* Defaults to `false`.
|
|
73
|
+
*/
|
|
74
|
+
critical?: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Defines a basic rule for mapping errors based on patterns.
|
|
78
|
+
* Used internally by `COMMON_ERROR_PATTERNS` and as a base for `ErrorMapping`.
|
|
79
|
+
*/
|
|
80
|
+
export interface BaseErrorMapping {
|
|
81
|
+
/**
|
|
82
|
+
* A string or regular expression to match against the error message.
|
|
83
|
+
* If a string is provided, it's typically used for substring matching (case-insensitive).
|
|
84
|
+
*/
|
|
85
|
+
pattern: string | RegExp;
|
|
86
|
+
/**
|
|
87
|
+
* The `BaseErrorCode` to assign if the pattern matches.
|
|
88
|
+
*/
|
|
89
|
+
errorCode: BaseErrorCode;
|
|
90
|
+
/**
|
|
91
|
+
* An optional custom message template for the mapped error.
|
|
92
|
+
* (Note: This property is defined but not directly used by `ErrorHandler.determineErrorCode`
|
|
93
|
+
* which focuses on `errorCode`. It's more relevant for custom mapping logic.)
|
|
94
|
+
*/
|
|
95
|
+
messageTemplate?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Extends `BaseErrorMapping` to include a factory function for creating
|
|
99
|
+
* specific error instances and additional context for the mapping.
|
|
100
|
+
* Used by `ErrorHandler.mapError`.
|
|
101
|
+
* @template T The type of `Error` this mapping will produce, defaults to `Error`.
|
|
102
|
+
*/
|
|
103
|
+
export interface ErrorMapping<T extends Error = Error> extends BaseErrorMapping {
|
|
104
|
+
/**
|
|
105
|
+
* A factory function that creates and returns an instance of the mapped error type `T`.
|
|
106
|
+
* @param error - The original error that occurred.
|
|
107
|
+
* @param context - Optional additional context provided in the mapping rule.
|
|
108
|
+
* @returns The newly created error instance.
|
|
109
|
+
*/
|
|
110
|
+
factory: (error: unknown, context?: Record<string, unknown>) => T;
|
|
111
|
+
/**
|
|
112
|
+
* Additional static context to be merged or passed to the `factory` function
|
|
113
|
+
* when this mapping rule is applied.
|
|
114
|
+
*/
|
|
115
|
+
additionalContext?: Record<string, unknown>;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A utility class providing static methods for comprehensive error handling.
|
|
119
|
+
*/
|
|
120
|
+
export declare class ErrorHandler {
|
|
121
|
+
/**
|
|
122
|
+
* Determines an appropriate `BaseErrorCode` for a given error.
|
|
123
|
+
* Checks `McpError` instances, `ERROR_TYPE_MAPPINGS`, and `COMMON_ERROR_PATTERNS`.
|
|
124
|
+
* Defaults to `BaseErrorCode.INTERNAL_ERROR`.
|
|
125
|
+
* @param error - The error instance or value to classify.
|
|
126
|
+
* @returns The determined error code.
|
|
127
|
+
*/
|
|
128
|
+
static determineErrorCode(error: unknown): BaseErrorCode;
|
|
129
|
+
/**
|
|
130
|
+
* Handles an error with consistent logging and optional transformation.
|
|
131
|
+
* Sanitizes input, determines error code, logs details, and can rethrow.
|
|
132
|
+
* @param error - The error instance or value that occurred.
|
|
133
|
+
* @param options - Configuration for handling the error.
|
|
134
|
+
* @returns The handled (and potentially transformed) error instance.
|
|
135
|
+
*/
|
|
136
|
+
static handleError(error: unknown, options: ErrorHandlerOptions): Error;
|
|
137
|
+
/**
|
|
138
|
+
* Maps an error to a specific error type `T` based on `ErrorMapping` rules.
|
|
139
|
+
* Returns original/default error if no mapping matches.
|
|
140
|
+
* @template T The target error type, extending `Error`.
|
|
141
|
+
* @param error - The error instance or value to map.
|
|
142
|
+
* @param mappings - An array of mapping rules to apply.
|
|
143
|
+
* @param defaultFactory - Optional factory for a default error if no mapping matches.
|
|
144
|
+
* @returns The mapped error of type `T`, or the original/defaulted error.
|
|
145
|
+
*/
|
|
146
|
+
static mapError<T extends Error>(error: unknown, mappings: ReadonlyArray<ErrorMapping<T>>, defaultFactory?: (error: unknown, context?: Record<string, unknown>) => T): T | Error;
|
|
147
|
+
/**
|
|
148
|
+
* Formats an error into a consistent object structure for API responses or structured logging.
|
|
149
|
+
* @param error - The error instance or value to format.
|
|
150
|
+
* @returns A structured representation of the error.
|
|
151
|
+
*/
|
|
152
|
+
static formatError(error: unknown): Record<string, unknown>;
|
|
153
|
+
/**
|
|
154
|
+
* Safely executes a function (sync or async) and handles errors using `ErrorHandler.handleError`.
|
|
155
|
+
* The error is always rethrown.
|
|
156
|
+
* @template T The expected return type of the function `fn`.
|
|
157
|
+
* @param fn - The function to execute.
|
|
158
|
+
* @param options - Error handling options (excluding `rethrow`).
|
|
159
|
+
* @returns A promise resolving with the result of `fn` if successful.
|
|
160
|
+
* @throws {McpError | Error} The error processed by `ErrorHandler.handleError`.
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* async function fetchData(userId: string, context: RequestContext) {
|
|
164
|
+
* return ErrorHandler.tryCatch(
|
|
165
|
+
* async () => {
|
|
166
|
+
* const response = await fetch(`/api/users/${userId}`);
|
|
167
|
+
* if (!response.ok) throw new Error(`Failed to fetch user: ${response.status}`);
|
|
168
|
+
* return response.json();
|
|
169
|
+
* },
|
|
170
|
+
* { operation: 'fetchUserData', context, input: { userId } }
|
|
171
|
+
* );
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
static tryCatch<T>(fn: () => Promise<T> | T, options: Omit<ErrorHandlerOptions, "rethrow">): Promise<T>;
|
|
176
|
+
}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview This module provides utilities for robust error handling.
|
|
3
|
+
* It defines structures for error context, options for handling errors,
|
|
4
|
+
* and mappings for classifying errors. The main `ErrorHandler` class
|
|
5
|
+
* offers static methods for consistent error processing, logging, and transformation.
|
|
6
|
+
* @module src/utils/internal/errorHandler
|
|
7
|
+
*/
|
|
8
|
+
import { BaseErrorCode, McpError } from "../../types-global/errors.js";
|
|
9
|
+
import { generateUUID, sanitizeInputForLogging } from "../index.js";
|
|
10
|
+
import { logger } from "./logger.js";
|
|
11
|
+
/**
|
|
12
|
+
* Maps standard JavaScript error constructor names to `BaseErrorCode` values.
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
const ERROR_TYPE_MAPPINGS = {
|
|
16
|
+
SyntaxError: BaseErrorCode.VALIDATION_ERROR,
|
|
17
|
+
TypeError: BaseErrorCode.VALIDATION_ERROR,
|
|
18
|
+
ReferenceError: BaseErrorCode.INTERNAL_ERROR,
|
|
19
|
+
RangeError: BaseErrorCode.VALIDATION_ERROR,
|
|
20
|
+
URIError: BaseErrorCode.VALIDATION_ERROR,
|
|
21
|
+
EvalError: BaseErrorCode.INTERNAL_ERROR,
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Array of `BaseErrorMapping` rules to classify errors by message/name patterns.
|
|
25
|
+
* Order matters: more specific patterns should precede generic ones.
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
const COMMON_ERROR_PATTERNS = [
|
|
29
|
+
{
|
|
30
|
+
pattern: /auth|unauthorized|unauthenticated|not.*logged.*in|invalid.*token|expired.*token/i,
|
|
31
|
+
errorCode: BaseErrorCode.UNAUTHORIZED,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
pattern: /permission|forbidden|access.*denied|not.*allowed/i,
|
|
35
|
+
errorCode: BaseErrorCode.FORBIDDEN,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
pattern: /not found|missing|no such|doesn't exist|couldn't find/i,
|
|
39
|
+
errorCode: BaseErrorCode.NOT_FOUND,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
pattern: /invalid|validation|malformed|bad request|wrong format|missing required/i,
|
|
43
|
+
errorCode: BaseErrorCode.VALIDATION_ERROR,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
pattern: /conflict|already exists|duplicate|unique constraint/i,
|
|
47
|
+
errorCode: BaseErrorCode.CONFLICT,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
pattern: /rate limit|too many requests|throttled/i,
|
|
51
|
+
errorCode: BaseErrorCode.RATE_LIMITED,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
pattern: /timeout|timed out|deadline exceeded/i,
|
|
55
|
+
errorCode: BaseErrorCode.TIMEOUT,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
pattern: /service unavailable|bad gateway|gateway timeout|upstream error/i,
|
|
59
|
+
errorCode: BaseErrorCode.SERVICE_UNAVAILABLE,
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
/**
|
|
63
|
+
* Creates a "safe" RegExp for testing error messages.
|
|
64
|
+
* Ensures case-insensitivity and removes the global flag.
|
|
65
|
+
* @param pattern - The string or RegExp pattern.
|
|
66
|
+
* @returns A new RegExp instance.
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
function createSafeRegex(pattern) {
|
|
70
|
+
if (pattern instanceof RegExp) {
|
|
71
|
+
let flags = pattern.flags.replace("g", "");
|
|
72
|
+
if (!flags.includes("i")) {
|
|
73
|
+
flags += "i";
|
|
74
|
+
}
|
|
75
|
+
return new RegExp(pattern.source, flags);
|
|
76
|
+
}
|
|
77
|
+
return new RegExp(pattern, "i");
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Retrieves a descriptive name for an error object or value.
|
|
81
|
+
* @param error - The error object or value.
|
|
82
|
+
* @returns A string representing the error's name or type.
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
function getErrorName(error) {
|
|
86
|
+
if (error instanceof Error) {
|
|
87
|
+
return error.name || "Error";
|
|
88
|
+
}
|
|
89
|
+
if (error === null) {
|
|
90
|
+
return "NullValueEncountered";
|
|
91
|
+
}
|
|
92
|
+
if (error === undefined) {
|
|
93
|
+
return "UndefinedValueEncountered";
|
|
94
|
+
}
|
|
95
|
+
if (typeof error === "object" &&
|
|
96
|
+
error !== null &&
|
|
97
|
+
error.constructor &&
|
|
98
|
+
typeof error.constructor.name === "string" &&
|
|
99
|
+
error.constructor.name !== "Object") {
|
|
100
|
+
return `${error.constructor.name}Encountered`;
|
|
101
|
+
}
|
|
102
|
+
return `${typeof error}Encountered`;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Extracts a message string from an error object or value.
|
|
106
|
+
* @param error - The error object or value.
|
|
107
|
+
* @returns The error message string.
|
|
108
|
+
* @private
|
|
109
|
+
*/
|
|
110
|
+
function getErrorMessage(error) {
|
|
111
|
+
if (error instanceof Error) {
|
|
112
|
+
return error.message;
|
|
113
|
+
}
|
|
114
|
+
if (error === null) {
|
|
115
|
+
return "Null value encountered as error";
|
|
116
|
+
}
|
|
117
|
+
if (error === undefined) {
|
|
118
|
+
return "Undefined value encountered as error";
|
|
119
|
+
}
|
|
120
|
+
if (typeof error === "string") {
|
|
121
|
+
return error;
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const str = String(error);
|
|
125
|
+
if (str === "[object Object]" && error !== null) {
|
|
126
|
+
try {
|
|
127
|
+
return `Non-Error object encountered: ${JSON.stringify(error)}`;
|
|
128
|
+
}
|
|
129
|
+
catch (stringifyError) {
|
|
130
|
+
return `Unstringifyable non-Error object encountered (constructor: ${error.constructor?.name || "Unknown"})`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return str;
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
return `Error converting error to string: ${e instanceof Error ? e.message : "Unknown conversion error"}`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* A utility class providing static methods for comprehensive error handling.
|
|
141
|
+
*/
|
|
142
|
+
export class ErrorHandler {
|
|
143
|
+
/**
|
|
144
|
+
* Determines an appropriate `BaseErrorCode` for a given error.
|
|
145
|
+
* Checks `McpError` instances, `ERROR_TYPE_MAPPINGS`, and `COMMON_ERROR_PATTERNS`.
|
|
146
|
+
* Defaults to `BaseErrorCode.INTERNAL_ERROR`.
|
|
147
|
+
* @param error - The error instance or value to classify.
|
|
148
|
+
* @returns The determined error code.
|
|
149
|
+
*/
|
|
150
|
+
static determineErrorCode(error) {
|
|
151
|
+
if (error instanceof McpError) {
|
|
152
|
+
return error.code;
|
|
153
|
+
}
|
|
154
|
+
const errorName = getErrorName(error);
|
|
155
|
+
const errorMessage = getErrorMessage(error);
|
|
156
|
+
if (errorName in ERROR_TYPE_MAPPINGS) {
|
|
157
|
+
return ERROR_TYPE_MAPPINGS[errorName];
|
|
158
|
+
}
|
|
159
|
+
for (const mapping of COMMON_ERROR_PATTERNS) {
|
|
160
|
+
const regex = createSafeRegex(mapping.pattern);
|
|
161
|
+
if (regex.test(errorMessage) || regex.test(errorName)) {
|
|
162
|
+
return mapping.errorCode;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return BaseErrorCode.INTERNAL_ERROR;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Handles an error with consistent logging and optional transformation.
|
|
169
|
+
* Sanitizes input, determines error code, logs details, and can rethrow.
|
|
170
|
+
* @param error - The error instance or value that occurred.
|
|
171
|
+
* @param options - Configuration for handling the error.
|
|
172
|
+
* @returns The handled (and potentially transformed) error instance.
|
|
173
|
+
*/
|
|
174
|
+
static handleError(error, options) {
|
|
175
|
+
const { context = {}, operation, input, rethrow = false, errorCode: explicitErrorCode, includeStack = true, critical = false, errorMapper, } = options;
|
|
176
|
+
const sanitizedInput = input !== undefined ? sanitizeInputForLogging(input) : undefined;
|
|
177
|
+
const originalErrorName = getErrorName(error);
|
|
178
|
+
const originalErrorMessage = getErrorMessage(error);
|
|
179
|
+
const originalStack = error instanceof Error ? error.stack : undefined;
|
|
180
|
+
let finalError;
|
|
181
|
+
let loggedErrorCode;
|
|
182
|
+
const errorDetailsSeed = error instanceof McpError &&
|
|
183
|
+
typeof error.details === "object" &&
|
|
184
|
+
error.details !== null
|
|
185
|
+
? { ...error.details }
|
|
186
|
+
: {};
|
|
187
|
+
const consolidatedDetails = {
|
|
188
|
+
...errorDetailsSeed,
|
|
189
|
+
...context,
|
|
190
|
+
originalErrorName,
|
|
191
|
+
originalMessage: originalErrorMessage,
|
|
192
|
+
};
|
|
193
|
+
if (originalStack &&
|
|
194
|
+
!(error instanceof McpError && error.details?.originalStack)) {
|
|
195
|
+
consolidatedDetails.originalStack = originalStack;
|
|
196
|
+
}
|
|
197
|
+
if (error instanceof McpError) {
|
|
198
|
+
loggedErrorCode = error.code;
|
|
199
|
+
finalError = errorMapper
|
|
200
|
+
? errorMapper(error)
|
|
201
|
+
: new McpError(error.code, error.message, consolidatedDetails);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
loggedErrorCode =
|
|
205
|
+
explicitErrorCode || ErrorHandler.determineErrorCode(error);
|
|
206
|
+
const message = `Error in ${operation}: ${originalErrorMessage}`;
|
|
207
|
+
finalError = errorMapper
|
|
208
|
+
? errorMapper(error)
|
|
209
|
+
: new McpError(loggedErrorCode, message, consolidatedDetails);
|
|
210
|
+
}
|
|
211
|
+
if (finalError !== error &&
|
|
212
|
+
error instanceof Error &&
|
|
213
|
+
finalError instanceof Error &&
|
|
214
|
+
!finalError.stack &&
|
|
215
|
+
error.stack) {
|
|
216
|
+
finalError.stack = error.stack;
|
|
217
|
+
}
|
|
218
|
+
const logRequestId = typeof context.requestId === "string" && context.requestId
|
|
219
|
+
? context.requestId
|
|
220
|
+
: generateUUID();
|
|
221
|
+
const logTimestamp = typeof context.timestamp === "string" && context.timestamp
|
|
222
|
+
? context.timestamp
|
|
223
|
+
: new Date().toISOString();
|
|
224
|
+
const logPayload = {
|
|
225
|
+
requestId: logRequestId,
|
|
226
|
+
timestamp: logTimestamp,
|
|
227
|
+
operation,
|
|
228
|
+
input: sanitizedInput,
|
|
229
|
+
critical,
|
|
230
|
+
errorCode: loggedErrorCode,
|
|
231
|
+
originalErrorType: originalErrorName,
|
|
232
|
+
finalErrorType: getErrorName(finalError),
|
|
233
|
+
...Object.fromEntries(Object.entries(context).filter(([key]) => key !== "requestId" && key !== "timestamp")),
|
|
234
|
+
};
|
|
235
|
+
if (finalError instanceof McpError && finalError.details) {
|
|
236
|
+
logPayload.errorDetails = finalError.details;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
logPayload.errorDetails = consolidatedDetails;
|
|
240
|
+
}
|
|
241
|
+
if (includeStack) {
|
|
242
|
+
const stack = finalError instanceof Error ? finalError.stack : originalStack;
|
|
243
|
+
if (stack) {
|
|
244
|
+
logPayload.stack = stack;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
logger.error(`Error in ${operation}: ${finalError.message || originalErrorMessage}`, logPayload);
|
|
248
|
+
if (rethrow) {
|
|
249
|
+
throw finalError;
|
|
250
|
+
}
|
|
251
|
+
return finalError;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Maps an error to a specific error type `T` based on `ErrorMapping` rules.
|
|
255
|
+
* Returns original/default error if no mapping matches.
|
|
256
|
+
* @template T The target error type, extending `Error`.
|
|
257
|
+
* @param error - The error instance or value to map.
|
|
258
|
+
* @param mappings - An array of mapping rules to apply.
|
|
259
|
+
* @param defaultFactory - Optional factory for a default error if no mapping matches.
|
|
260
|
+
* @returns The mapped error of type `T`, or the original/defaulted error.
|
|
261
|
+
*/
|
|
262
|
+
static mapError(error, mappings, defaultFactory) {
|
|
263
|
+
const errorMessage = getErrorMessage(error);
|
|
264
|
+
const errorName = getErrorName(error);
|
|
265
|
+
for (const mapping of mappings) {
|
|
266
|
+
const regex = createSafeRegex(mapping.pattern);
|
|
267
|
+
if (regex.test(errorMessage) || regex.test(errorName)) {
|
|
268
|
+
return mapping.factory(error, mapping.additionalContext);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (defaultFactory) {
|
|
272
|
+
return defaultFactory(error);
|
|
273
|
+
}
|
|
274
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Formats an error into a consistent object structure for API responses or structured logging.
|
|
278
|
+
* @param error - The error instance or value to format.
|
|
279
|
+
* @returns A structured representation of the error.
|
|
280
|
+
*/
|
|
281
|
+
static formatError(error) {
|
|
282
|
+
if (error instanceof McpError) {
|
|
283
|
+
return {
|
|
284
|
+
code: error.code,
|
|
285
|
+
message: error.message,
|
|
286
|
+
details: typeof error.details === "object" && error.details !== null
|
|
287
|
+
? error.details
|
|
288
|
+
: {},
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
if (error instanceof Error) {
|
|
292
|
+
return {
|
|
293
|
+
code: ErrorHandler.determineErrorCode(error),
|
|
294
|
+
message: error.message,
|
|
295
|
+
details: { errorType: error.name || "Error" },
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
code: BaseErrorCode.UNKNOWN_ERROR,
|
|
300
|
+
message: getErrorMessage(error),
|
|
301
|
+
details: { errorType: getErrorName(error) },
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Safely executes a function (sync or async) and handles errors using `ErrorHandler.handleError`.
|
|
306
|
+
* The error is always rethrown.
|
|
307
|
+
* @template T The expected return type of the function `fn`.
|
|
308
|
+
* @param fn - The function to execute.
|
|
309
|
+
* @param options - Error handling options (excluding `rethrow`).
|
|
310
|
+
* @returns A promise resolving with the result of `fn` if successful.
|
|
311
|
+
* @throws {McpError | Error} The error processed by `ErrorHandler.handleError`.
|
|
312
|
+
* @example
|
|
313
|
+
* ```typescript
|
|
314
|
+
* async function fetchData(userId: string, context: RequestContext) {
|
|
315
|
+
* return ErrorHandler.tryCatch(
|
|
316
|
+
* async () => {
|
|
317
|
+
* const response = await fetch(`/api/users/${userId}`);
|
|
318
|
+
* if (!response.ok) throw new Error(`Failed to fetch user: ${response.status}`);
|
|
319
|
+
* return response.json();
|
|
320
|
+
* },
|
|
321
|
+
* { operation: 'fetchUserData', context, input: { userId } }
|
|
322
|
+
* );
|
|
323
|
+
* }
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
static async tryCatch(fn, options) {
|
|
327
|
+
try {
|
|
328
|
+
return await Promise.resolve(fn());
|
|
329
|
+
}
|
|
330
|
+
catch (error) {
|
|
331
|
+
// ErrorHandler.handleError will return the error to be thrown.
|
|
332
|
+
throw ErrorHandler.handleError(error, { ...options, rethrow: true });
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Barrel file for internal utility modules.
|
|
3
|
+
* This file re-exports core internal utilities related to error handling,
|
|
4
|
+
* logging, and request context management.
|
|
5
|
+
* @module src/utils/internal
|
|
6
|
+
*/
|
|
7
|
+
export * from "./errorHandler.js";
|
|
8
|
+
export * from "./logger.js";
|
|
9
|
+
export * from "./requestContext.js";
|