{"version":3,"sources":["../src/code.ts","../src/output.ts","../src/exception.ts","../src/utils.ts","../src/catch.ts"],"names":["HttpStatusCode","HttpStatusCodeMap","Map","GrpcStatusCode","GrpcStatusCodeMap","StatusCodeConvert","code","CommonErrorCode","isJsonResult","obj","message","isCodeError","safeStringify","value","undefined","JSON","stringify","String","Output","ok","msg","data","fail","err","Helper","isError","trim","paginate","items","total","page","pageSize","safeTotal","Math","max","floor","safePage","safePageSize","totalPages","ceil","Array","isArray","pagination","hasNext","hasPrev","withMeta","meta","Object","keys","length","globalConfig","enableStackTrace","process","env","NODE_ENV","logFormat","maxStackLength","setExceptionConfig","config","getExceptionConfig","ExceptionHandler","target","identifier","IOCContainer","getIdentifier","prototype","Exception","Error","saveClass","type","status","span","timestamp","context","stack","Date","now","setCode","setStatus","setStack","name","isNumber","setMessage","substring","setSpan","setContext","handler","ctx","requestId","path","originalPath","method","userAgent","get","startTime","endTime","duration","log","encoding","output","error","Logger","fallbackOutput","_error","isGrpc","protocol","isWebSocket","fallbackResponse","rpc","callback","details","body","Buffer","byteLength","websocket","send","res","end","logData","toISOString","level","logMessage","formatTextLog","updateSpan","SpanStatusCode","ERROR","setAttribute","ATTR_HTTP_RESPONSE_STATUS_CODE","ATTR_HTTP_REQUEST_METHOD","ATTR_URL_FULL","url","responseBody","customErrorFormat","writableEnded","finished","Warn","toJSON","PREVENT_NEXT_PROCESS","prevent","Promise","reject","isException","toSafeError","isNetworkError","networkErrorCodes","includes","isExceptionConstructor","shouldCatch","catchTypes","some","ErrorType","parseOptions","args","first","exception","errorTypes","options","Catch","propertyKey","descriptor","originalMethod","methodArgs","result","apply","safeError","ExceptionClass","errorMessage","useCustomDefaults","errorCode","GENERAL_ERROR","errorStatus","preserveStack","finalException","transform","suppress","defineProperty","configurable"],"mappings":";;;;;;;;;;;;;;;;;;AAcO,IAAKA,cAAAA,6BAAAA,eAAAA,EAAAA;AAQT,EAAAA,eAAAA,CAAAA,eAAAA,CAAA,UAAA,CAAA,GAAA,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,OAAAA,CAAQiB,SAAAA,GAC3BjB,QAAQiB,SAAAA,CAAUnB,SAAAA,EAAgBU,SAAAA,CAAAA,GAClCV,SAAAA;AAGJ,QAAA,IAAIE,QAAQkB,QAAAA,EAAU;AACpB,UAAA,OAAOhK,MAAAA;AACT,QAAA;AAEA,QAAA,MAAM8J,cAAAA;AACR,MAAA;AACF,IAAA,CAAA;AAGA7H,IAAAA,MAAAA,CAAOgI,cAAAA,CAAehB,UAAAA,CAAWlJ,KAAAA,EAAO,MAAA,EAAQ;AAC9CA,MAAAA,KAAAA,EAAOmJ,cAAAA,CAAehF,IAAAA;MACtBgG,YAAAA,EAAc;KAChB,CAAA;AAGA,IAAA,IAAIhB,cAAAA,CAAe/G,WAAWnC,MAAAA,EAAW;AACvCiC,MAAAA,MAAAA,CAAOgI,cAAAA,CAAehB,UAAAA,CAAWlJ,KAAAA,EAAO,QAAA,EAAU;AAChDA,QAAAA,KAAAA,EAAOmJ,cAAAA,CAAe/G,MAAAA;QACtB+H,YAAAA,EAAc;OAChB,CAAA;AACF,IAAA;AAEA,IAAA,OAAOjB,UAAAA;AACT,EAAA,CAAA;AACF;AA1HgBF,MAAAA,CAAAA,KAAAA,EAAAA,OAAAA,CAAAA","file":"index.mjs","sourcesContent":["/*\n * @Description: \n * @Usage: \n * @Author: richen\n * @Date: 2021-11-19 00:53:19\n * @LastEditTime: 2023-01-13 10:02:11\n */\n\n/**\n * HttpStatusCode\n *\n * @export\n * @enum {number}\n */\nexport enum HttpStatusCode {\n\n  /**\n   * The server has received the request headers and the client should proceed to send the request body\n   * (in the case of a request for which a body needs to be sent; for example, a POST request).\n   * Sending a large request body to a server after a request has been rejected for inappropriate headers would be inefficient.\n   * To have a server check the request's headers, a client must send Expect: 100-continue as a header in its initial request\n   * and receive a 100 Continue status code in response before sending the body. The response 417 Expectation Failed indicates the request should not be continued.\n   */\n  CONTINUE = 100,\n\n  /**\n   * The requester has asked the server to switch protocols and the server has agreed to do so.\n   */\n  SWITCHING_PROTOCOLS = 101,\n\n  /**\n   * A WebDAV request may contain many sub-requests involving file operations, requiring a long time to complete the request.\n   * This code indicates that the server has received and is processing the request, but no response is available yet.\n   * This prevents the client from timing out and assuming the request was lost.\n   */\n  PROCESSING = 102,\n\n  /**\n   * Standard response for successful HTTP requests.\n   * The actual response will depend on the request method used.\n   * In a GET request, the response will contain an entity corresponding to the requested resource.\n   * In a POST request, the response will contain an entity describing or containing the result of the action.\n   */\n  OK = 200,\n\n  /**\n   * The request has been fulfilled, resulting in the creation of a new resource.\n   */\n  CREATED = 201,\n\n  /**\n   * The request has been accepted for processing, but the processing has not been completed.\n   * The request might or might not be eventually acted upon, and may be disallowed when processing occurs.\n   */\n  ACCEPTED = 202,\n\n  /**\n   * SINCE HTTP/1.1\n   * The server is a transforming proxy that received a 200 OK from its origin,\n   * but is returning a modified version of the origin's response.\n   */\n  NON_AUTHORITATIVE_INFORMATION = 203,\n\n  /**\n   * The server successfully processed the request and is not returning any content.\n   */\n  NO_CONTENT = 204,\n\n  /**\n   * The server successfully processed the request, but is not returning any content.\n   * Unlike a 204 response, this response requires that the requester reset the document view.\n   */\n  RESET_CONTENT = 205,\n\n  /**\n   * The server is delivering only part of the resource (byte serving) due to a range header sent by the client.\n   * The range header is used by HTTP clients to enable resuming of interrupted downloads,\n   * or split a download into multiple simultaneous streams.\n   */\n  PARTIAL_CONTENT = 206,\n\n  /**\n   * The message body that follows is an XML message and can contain a number of separate response codes,\n   * depending on how many sub-requests were made.\n   */\n  MULTI_STATUS = 207,\n\n  /**\n   * The members of a DAV binding have already been enumerated in a preceding part of the (multistatus) response,\n   * and are not being included again.\n   */\n  ALREADY_REPORTED = 208,\n\n  /**\n   * The server has fulfilled a request for the resource,\n   * and the response is a representation of the result of one or more instance-manipulations applied to the current instance.\n   */\n  IM_USED = 226,\n\n  /**\n   * Indicates multiple options for the resource from which the client may choose (via agent-driven content negotiation).\n   * For example, this code could be used to present multiple video format options,\n   * to list files with different filename extensions, or to suggest word-sense disambiguation.\n   */\n  MULTIPLE_CHOICES = 300,\n\n  /**\n   * This and all future requests should be directed to the given URI.\n   */\n  MOVED_PERMANENTLY = 301,\n\n  /**\n   * This is an example of industry practice contradicting the standard.\n   * The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect\n   * (the original describing phrase was \"Moved Temporarily\"), but popular browsers implemented 302\n   * with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307\n   * to distinguish between the two behaviours. However, some Web applications and frameworks\n   * use the 302 status code as if it were the 303.\n   */\n  FOUND = 302,\n\n  /**\n   * SINCE HTTP/1.1\n   * The response to the request can be found under another URI using a GET method.\n   * When received in response to a POST (or PUT/DELETE), the client should presume that\n   * the server has received the data and should issue a redirect with a separate GET message.\n   */\n  SEE_OTHER = 303,\n\n  /**\n   * Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match.\n   * In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy.\n   */\n  NOT_MODIFIED = 304,\n\n  /**\n   * SINCE HTTP/1.1\n   * The requested resource is available only through a proxy, the address for which is provided in the response.\n   * Many HTTP clients (such as Mozilla and Internet Explorer) do not correctly handle responses with this status code, primarily for security reasons.\n   */\n  USE_PROXY = 305,\n\n  /**\n   * No longer used. Originally meant \"Subsequent requests should use the specified proxy.\"\n   */\n  SWITCH_PROXY = 306,\n\n  /**\n   * SINCE HTTP/1.1\n   * In this case, the request should be repeated with another URI; however, future requests should still use the original URI.\n   * In contrast to how 302 was historically implemented, the request method is not allowed to be changed when reissuing the original request.\n   * For example, a POST request should be repeated using another POST request.\n   */\n  TEMPORARY_REDIRECT = 307,\n\n  /**\n   * The request and all future requests should be repeated using another URI.\n   * 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change.\n   * So, for example, submitting a form to a permanently redirected resource may continue smoothly.\n   */\n  PERMANENT_REDIRECT = 308,\n\n  /**\n   * The server cannot or will not process the request due to an apparent client error\n   * (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing).\n   */\n  BAD_REQUEST = 400,\n\n  /**\n   * Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet\n   * been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the\n   * requested resource. See Basic access authentication and Digest access authentication. 401 semantically means\n   * \"unauthenticated\",i.e. the user does not have the necessary credentials.\n   */\n  UNAUTHORIZED = 401,\n\n  /**\n   * Reserved for future use. The original intention was that this code might be used as part of some form of digital\n   * cash or micro payment scheme, but that has not happened, and this code is not usually used.\n   * Google Developers API uses this status if a particular developer has exceeded the daily limit on requests.\n   */\n  PAYMENT_REQUIRED = 402,\n\n  /**\n   * The request was valid, but the server is refusing action.\n   * The user might not have the necessary permissions for a resource.\n   */\n  FORBIDDEN = 403,\n\n  /**\n   * The requested resource could not be found but may be available in the future.\n   * Subsequent requests by the client are permissible.\n   */\n  NOT_FOUND = 404,\n\n  /**\n   * A request method is not supported for the requested resource;\n   * for example, a GET request on a form that requires data to be presented via POST, or a PUT request on a read-only resource.\n   */\n  METHOD_NOT_ALLOWED = 405,\n\n  /**\n   * The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.\n   */\n  NOT_ACCEPTABLE = 406,\n\n  /**\n   * The client must first authenticate itself with the proxy.\n   */\n  PROXY_AUTHENTICATION_REQUIRED = 407,\n\n  /**\n   * The server timed out waiting for the request.\n   * According to HTTP specifications:\n   * \"The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time.\"\n   */\n  REQUEST_TIMEOUT = 408,\n\n  /**\n   * Indicates that the request could not be processed because of conflict in the request,\n   * such as an edit conflict between multiple simultaneous updates.\n   */\n  CONFLICT = 409,\n\n  /**\n   * Indicates that the resource requested is no longer available and will not be available again.\n   * This should be used when a resource has been intentionally removed and the resource should be purged.\n   * Upon receiving a 410 status code, the client should not request the resource in the future.\n   * Clients such as search engines should remove the resource from their indices.\n   * Most use cases do not require clients and search engines to purge the resource, and a \"404 Not Found\" may be used instead.\n   */\n  GONE = 410,\n\n  /**\n   * The request did not specify the length of its content, which is required by the requested resource.\n   */\n  LENGTH_REQUIRED = 411,\n\n  /**\n   * The server does not meet one of the preconditions that the requester put on the request.\n   */\n  PRECONDITION_FAILED = 412,\n\n  /**\n   * The request is larger than the server is willing or able to process. Previously called \"Request Entity Too Large\".\n   */\n  PAYLOAD_TOO_LARGE = 413,\n\n  /**\n   * The URI provided was too long for the server to process. Often the result of too much data being encoded as a query-string of a GET request,\n   * in which case it should be converted to a POST request.\n   * Called \"Request-URI Too Long\" previously.\n   */\n  URI_TOO_LONG = 414,\n\n  /**\n   * The request entity has a media type which the server or resource does not support.\n   * For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.\n   */\n  UNSUPPORTED_MEDIA_TYPE = 415,\n\n  /**\n   * The client has asked for a portion of the file (byte serving), but the server cannot supply that portion.\n   * For example, if the client asked for a part of the file that lies beyond the end of the file.\n   * Called \"Requested Range Not Satisfiable\" previously.\n   */\n  RANGE_NOT_SATISFIABLE = 416,\n\n  /**\n   * The server cannot meet the requirements of the Expect request-header field.\n   */\n  EXPECTATION_FAILED = 417,\n\n  /**\n   * This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 2324, Hyper Text Coffee Pot Control Protocol,\n   * and is not expected to be implemented by actual HTTP servers. The RFC specifies this code should be returned by\n   * teapots requested to brew coffee. This HTTP status is used as an Easter egg in some websites, including Google.com.\n   */\n  I_AM_A_TEAPOT = 418,\n\n  /**\n   * The request was directed at a server that is not able to produce a response (for example because a connection reuse).\n   */\n  MISDIRECTED_REQUEST = 421,\n\n  /**\n   * The request was well-formed but was unable to be followed due to semantic errors.\n   */\n  UNPROCESSABLE_ENTITY = 422,\n\n  /**\n   * The resource that is being accessed is locked.\n   */\n  LOCKED = 423,\n\n  /**\n   * The request failed due to failure of a previous request (e.g., a PROPPATCH).\n   */\n  FAILED_DEPENDENCY = 424,\n\n  /**\n   * The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field.\n   */\n  UPGRADE_REQUIRED = 426,\n\n  /**\n   * The origin server requires the request to be conditional.\n   * Intended to prevent \"the 'lost update' problem, where a client\n   * GETs a resource's state, modifies it, and PUTs it back to the server,\n   * when meanwhile a third party has modified the state on the server, leading to a conflict.\"\n   */\n  PRECONDITION_REQUIRED = 428,\n\n  /**\n   * The user has sent too many requests in a given amount of time. Intended for use with rate-limiting schemes.\n   */\n  TOO_MANY_REQUESTS = 429,\n\n  /**\n   * The server is unwilling to process the request because either an individual header field,\n   * or all the header fields collectively, are too large.\n   */\n  REQUEST_HEADER_FIELDS_TOO_LARGE = 431,\n\n  /**\n   * A server operator has received a legal demand to deny access to a resource or to a set of resources\n   * that includes the requested resource. The code 451 was chosen as a reference to the novel Fahrenheit 451.\n   */\n  UNAVAILABLE_FOR_LEGAL_REASONS = 451,\n\n  /**\n   * A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.\n   */\n  INTERNAL_SERVER_ERROR = 500,\n\n  /**\n   * The server either does not recognize the request method, or it lacks the ability to fulfill the request.\n   * Usually this implies future availability (e.g., a new feature of a web-service API).\n   */\n  NOT_IMPLEMENTED = 501,\n\n  /**\n   * The server was acting as a gateway or proxy and received an invalid response from the upstream server.\n   */\n  BAD_GATEWAY = 502,\n\n  /**\n   * The server is currently unavailable (because it is overloaded or down for maintenance).\n   * Generally, this is a temporary state.\n   */\n  SERVICE_UNAVAILABLE = 503,\n\n  /**\n   * The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.\n   */\n  GATEWAY_TIMEOUT = 504,\n\n  /**\n   * The server does not support the HTTP protocol version used in the request\n   */\n  HTTP_VERSION_NOT_SUPPORTED = 505,\n\n  /**\n   * Transparent content negotiation for the request results in a circular reference.\n   */\n  VARIANT_ALSO_NEGOTIATES = 506,\n\n  /**\n   * The server is unable to store the representation needed to complete the request.\n   */\n  INSUFFICIENT_STORAGE = 507,\n\n  /**\n   * The server detected an infinite loop while processing the request.\n   */\n  LOOP_DETECTED = 508,\n\n  /**\n   * Further extensions to the request are required for the server to fulfill it.\n   */\n  NOT_EXTENDED = 510,\n\n  /**\n   * The client needs to authenticate to gain network access.\n   * Intended for use by intercepting proxies used to control access to the network (e.g., \"captive portals\" used\n   * to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot).\n   */\n  NETWORK_AUTHENTICATION_REQUIRED = 511\n}\n\n/**\n * HttpStatusCodeMap\n */\nexport const HttpStatusCodeMap = new Map([\n  [100, \"CONTINUE\"],\n  [101, \"SWITCHING_PROTOCOLS\"],\n  [102, \"PROCESSING\"],\n  [200, \"OK\"],\n  [201, \"CREATED\"],\n  [202, \"ACCEPTED\"],\n  [203, \"NON_AUTHORITATIVE_INFORMATION\"],\n  [204, \"NO_CONTENT\"],\n  [205, \"RESET_CONTENT\"],\n  [206, \"PARTIAL_CONTENT\"],\n  [207, \"MULTI_STATUS\"],\n  [208, \"ALREADY_REPORTED\"],\n  [226, \"IM_USED\"],\n  [300, \"MULTIPLE_CHOICES\"],\n  [301, \"MOVED_PERMANENTLY\"],\n  [302, \"FOUND\"],\n  [303, \"SEE_OTHER\"],\n  [304, \"NOT_MODIFIED\"],\n  [305, \"USE_PROXY\"],\n  [306, \"SWITCH_PROXY\"],\n  [307, \"TEMPORARY_REDIRECT\"],\n  [308, \"PERMANENT_REDIRECT\"],\n  [400, \"BAD_REQUEST\"],\n  [401, \"UNAUTHORIZED\"],\n  [402, \"PAYMENT_REQUIRED\"],\n  [403, \"FORBIDDEN\"],\n  [404, \"NOT_FOUND\"],\n  [405, \"METHOD_NOT_ALLOWED\"],\n  [406, \"NOT_ACCEPTABLE\"],\n  [407, \"PROXY_AUTHENTICATION_REQUIRED\"],\n  [408, \"REQUEST_TIMEOUT\"],\n  [409, \"CONFLICT\"],\n  [410, \"GONE\"],\n  [411, \"LENGTH_REQUIRED\"],\n  [412, \"PRECONDITION_FAILED\"],\n  [413, \"PAYLOAD_TOO_LARGE\"],\n  [414, \"URI_TOO_LONG\"],\n  [415, \"UNSUPPORTED_MEDIA_TYPE\"],\n  [416, \"RANGE_NOT_SATISFIABLE\"],\n  [417, \"EXPECTATION_FAILED\"],\n  [418, \"I_AM_A_TEAPOT\"],\n  [421, \"MISDIRECTED_REQUEST\"],\n  [422, \"UNPROCESSABLE_ENTITY\"],\n  [423, \"LOCKED\"],\n  [424, \"FAILED_DEPENDENCY\"],\n  [426, \"UPGRADE_REQUIRED\"],\n  [428, \"PRECONDITION_REQUIRED\"],\n  [429, \"TOO_MANY_REQUESTS\"],\n  [431, \"REQUEST_HEADER_FIELDS_TOO_LARGE\"],\n  [451, \"UNAVAILABLE_FOR_LEGAL_REASONS\"],\n  [500, \"INTERNAL_SERVER_ERROR\"],\n  [501, \"NOT_IMPLEMENTED\"],\n  [502, \"BAD_GATEWAY\"],\n  [503, \"SERVICE_UNAVAILABLE\"],\n  [504, \"GATEWAY_TIMEOUT\"],\n  [505, \"HTTP_VERSION_NOT_SUPPORTED\"],\n  [506, \"VARIANT_ALSO_NEGOTIATES\"],\n  [507, \"INSUFFICIENT_STORAGE\"],\n  [508, \"LOOP_DETECTED\"],\n  [510, \"NOT_EXTENDED\"],\n  [511, \"NETWORK_AUTHENTICATION_REQUIRED\"],\n]);\n\n/**\n * GrpcStatusCode\n *\n * @export\n * @enum {number}\n */\nexport enum GrpcStatusCode {\n  OK = 0,\n  CANCELLED = 1,\n  UNKNOWN = 2,\n  INVALID_ARGUMENT = 3,\n  DEADLINE_EXCEEDED = 4,\n  NOT_FOUND = 5,\n  ALREADY_EXISTS = 6,\n  PERMISSION_DENIED = 7,\n  RESOURCE_EXHAUSTED = 8,\n  FAILED_PRECONDITION = 9,\n  ABORTED = 10,\n  OUT_OF_RANGE = 11,\n  UNIMPLEMENTED = 12,\n  INTERNAL = 13,\n  UNAVAILABLE = 14,\n  DATA_LOSS = 15,\n  UNAUTHENTICATED = 16\n}\n/**\n * GrpcStatusCodeMap\n */\nexport const GrpcStatusCodeMap = new Map([\n  [0, \"OK\"],\n  [1, \"CANCELLED\"],\n  [2, \"UNKNOWN\"],\n  [3, \"INVALID_ARGUMENT\"],\n  [4, \"DEADLINE_EXCEEDED\"],\n  [5, \"NOT_FOUND\"],\n  [6, \"ALREADY_EXISTS\"],\n  [7, \"PERMISSION_DENIED\"],\n  [8, \"RESOURCE_EXHAUSTED\"],\n  [9, \"FAILED_PRECONDITION\"],\n  [10, \"ABORTED\"],\n  [11, \"OUT_OF_RANGE\"],\n  [12, \"UNIMPLEMENTED\"],\n  [13, \"INTERNAL\"],\n  [14, \"UNAVAILABLE\"],\n  [15, \"DATA_LOSS\"],\n  [16, \"UNAUTHENTICATED\"],\n]);\n\n/**\n * Convert HttpStatusCode to GrpcStatusCode\n * https://chromium.googlesource.com/external/github.com/grpc/grpc/+/refs/heads/chromium-deps/2016-10-25/doc/http-grpc-status-mapping.md\n * @export\n * @param {HttpStatusCode} code\n * @returns {*}  {GrpcStatusCode}\n */\nexport function StatusCodeConvert(code: HttpStatusCode): GrpcStatusCode {\n  switch (code) {\n    case 200: //HttpStatusCode.OK:\n      return 0;//GrpcStatusCode.OK;\n    case 304: //HttpStatusCode.NOT_MODIFIED:\n      return 1; //GrpcStatusCode.CANCELLED;\n    case 400: //HttpStatusCode.BAD_REQUEST:\n      return 3; //GrpcStatusCode.INVALID_ARGUMENT;\n    case 408: //HttpStatusCode.REQUEST_TIMEOUT:\n      return 4; //GrpcStatusCode.DEADLINE_EXCEEDED;\n    case 404: //HttpStatusCode.NOT_FOUND:\n      return 5; //GrpcStatusCode.NOT_FOUND;\n    case 409: //HttpStatusCode.CONFLICT:\n      return 6; //GrpcStatusCode.ALREADY_EXISTS;\n    case 403: //HttpStatusCode.FORBIDDEN:\n      return 7; //GrpcStatusCode.PERMISSION_DENIED;\n    case 429: //HttpStatusCode.TOO_MANY_REQUESTS:\n      return 8; //GrpcStatusCode.RESOURCE_EXHAUSTED;\n    case 412: //HttpStatusCode.PRECONDITION_FAILED:\n      return 9; //GrpcStatusCode.FAILED_PRECONDITION;\n    case 421: //HttpStatusCode.MISDIRECTED_REQUEST:\n      return 10; //GrpcStatusCode.ABORTED;\n    case 416: //HttpStatusCode.RANGE_NOT_SATISFIABLE:\n      return 11; //GrpcStatusCode.OUT_OF_RANGE;\n    case 501: //HttpStatusCode.NOT_IMPLEMENTED:\n      return 12; //GrpcStatusCode.UNIMPLEMENTED;\n    case 500: //HttpStatusCode.INTERNAL_SERVER_ERROR:\n      return 13; //GrpcStatusCode.INTERNAL;\n    case 503: //HttpStatusCode.SERVICE_UNAVAILABLE:\n      return 14; //GrpcStatusCode.UNAVAILABLE;\n    case 410: //HttpStatusCode.GONE:\n      return 15; //GrpcStatusCode.DATA_LOSS;\n    case 401: //HttpStatusCode.UNAUTHORIZED:\n      return 16; //GrpcStatusCode.UNAUTHENTICATED;\n\n    default:\n      return 2; //GrpcStatusCode.UNKNOWN;\n  }\n} \n\n/**\n * Common error codes enum\n */\nexport enum CommonErrorCode {\n  SUCCESS = 0,\n  GENERAL_ERROR = 1,\n  VALIDATION_ERROR = 1001,\n  AUTHENTICATION_ERROR = 1002,\n  AUTHORIZATION_ERROR = 1003,\n  RESOURCE_NOT_FOUND = 1004,\n  RESOURCE_CONFLICT = 1005,\n  RATE_LIMIT_EXCEEDED = 1006,\n  INTERNAL_SERVER_ERROR = 1007,\n  SERVICE_UNAVAILABLE = 1008,\n  TIMEOUT_ERROR = 1009,\n  NETWORK_ERROR = 1010\n}","/*\n * @Description: output data\n * @Usage: \n * @Author: richen\n * @Date: 2024-01-03 22:03:34\n * @LastEditTime: 2024-03-15 06:16:52\n * @License: BSD (3-Clause)\n * @Copyright (c): <richenlin(at)gmail.com>\n */\n\nimport { Helper } from \"koatty_lib\";\n\n/**\n * Interface for Api output\n */\nexport interface JsonResult<T = any> {\n  code: number; // 错误码\n  message: string; // 消息内容\n  data: T; // 数据\n}\n\n/**\n * Interface for Api CodeError\n */\nexport interface CodeError {\n  code?: number;\n  message?: string;\n  data?: unknown;\n}\n\n/**\n * Type guard for JsonResult\n * \n * @param {unknown} obj - Object to check\n * @returns {obj is JsonResult} Type guard result\n */\nfunction isJsonResult(obj: unknown): obj is JsonResult {\n  return !!(\n    obj &&\n    typeof obj === 'object' &&\n    'code' in obj &&\n    'message' in obj &&\n    'data' in obj &&\n    typeof (obj as JsonResult).code === 'number' &&\n    typeof (obj as JsonResult).message === 'string'\n  );\n}\n\n/**\n * Type guard for CodeError\n * \n * @param {unknown} obj - Object to check\n * @returns {obj is CodeError} Type guard result\n */\nfunction isCodeError(obj: unknown): obj is CodeError {\n  return !!(\n    obj &&\n    typeof obj === 'object' &&\n    ('code' in obj || 'message' in obj || 'data' in obj)\n  );\n}\n\n/**\n * Safe string conversion\n * \n * @param {unknown} value - Value to convert\n * @returns {string} String representation\n */\nfunction safeStringify(value: unknown): string {\n  if (typeof value === 'string') {\n    return value;\n  }\n  \n  if (value === null || value === undefined) {\n    return '';\n  }\n  \n  if (typeof value === 'object') {\n    try {\n      return JSON.stringify(value);\n    } catch {\n      return '[Object object]';\n    }\n  }\n  \n  return String(value);\n}\n\nexport class Output {\n  /**\n   * Response to normalize json format content for success\n   *\n   * @template T\n   * @param {string | JsonResult<T>} msg - Message or JsonResult object\n   * @param {T} [data] - Response data\n   * @param {number} [code=0] - Success code, default 0\n   * @returns {JsonResult<T>} Normalized success response\n   */\n  public static ok<T = any>(msg: string | JsonResult<T>, data?: T, code = 0): JsonResult<T> {\n    // Validate inputs\n    if (typeof code !== 'number' || code < 0) {\n      code = 0;\n    }\n    \n    // Handle JsonResult input\n    if (isJsonResult(msg)) {\n      return {\n        code: typeof msg.code === 'number' ? msg.code : code,\n        message: safeStringify(msg.message),\n        data: msg.data\n      };\n    }\n    \n    return {\n      code: code,\n      message: safeStringify(msg),\n      data: data as T\n    };\n  }\n\n  /**\n   * Response to normalize json format content for fail\n   *\n   * @template T\n   * @param {Error | CodeError | string | unknown} err - Error object, message, or unknown error\n   * @param {T} [data] - Additional error data\n   * @param {number} [code=1] - Error code, default 1\n   * @returns {JsonResult<T>} Normalized error response\n   */\n  public static fail<T = any>(err?: Error | CodeError | string | unknown, data?: T, code = 1): JsonResult<T> {\n    // Validate code input\n    if (typeof code !== 'number' || code < 1) {\n      code = 1;\n    }\n    \n    // Handle Error objects\n    if (Helper.isError(err)) {\n      return {\n        code: code,\n        message: (<any>err).message || 'Unknown error',\n        data: data as T\n      };\n    }\n    \n    // Handle CodeError objects\n    if (isCodeError(err)) {\n      return {\n        code: typeof err.code === 'number' && err.code > 0 ? err.code : code,\n        message: safeStringify(err.message) || 'Unknown error',\n        data: (err.data as T) || data as T\n      };\n    }\n    \n    // Handle string messages\n    if (typeof err === 'string') {\n      return {\n        code: code,\n        message: err.trim() || 'Unknown error',\n        data: data as T\n      };\n    }\n    \n    // Handle unknown errors\n    return {\n      code: code,\n      message: safeStringify(err) || 'Unknown error occurred',\n      data: data as T\n    };\n  }\n\n  /**\n   * Create a paginated response\n   * \n   * @template T\n   * @param {T[]} items - Array of items\n   * @param {number} total - Total count\n   * @param {number} page - Current page (1-based)\n   * @param {number} pageSize - Items per page\n   * @param {string} [message='Success'] - Response message\n   * @returns {JsonResult} Paginated response\n   */\n  public static paginate<T>(\n    items: T[],\n    total: number,\n    page: number,\n    pageSize: number,\n    message = 'Success'\n  ): JsonResult<{\n    items: T[];\n    pagination: {\n      total: number;\n      page: number;\n      pageSize: number;\n      totalPages: number;\n      hasNext: boolean;\n      hasPrev: boolean;\n    };\n  }> {\n    // Validate inputs\n    const safeTotal = Math.max(0, Math.floor(total));\n    const safePage = Math.max(1, Math.floor(page));\n    const safePageSize = Math.max(1, Math.floor(pageSize));\n    const totalPages = Math.ceil(safeTotal / safePageSize);\n    \n    return this.ok(message, {\n      items: Array.isArray(items) ? items : [],\n      pagination: {\n        total: safeTotal,\n        page: safePage,\n        pageSize: safePageSize,\n        totalPages,\n        hasNext: safePage < totalPages,\n        hasPrev: safePage > 1\n      }\n    });\n  }\n\n  /**\n   * Create a response with metadata\n   * \n   * @template T\n   * @param {string} message - Response message\n   * @param {T} data - Response data\n   * @param {Record<string, unknown>} [meta] - Additional metadata\n   * @param {number} [code=0] - Response code\n   * @returns {JsonResult} Response with metadata\n   */\n  public static withMeta<T>(\n    message: string,\n    data: T,\n    meta?: Record<string, unknown>,\n    code = 0\n  ): JsonResult<{ data: T; meta?: Record<string, unknown> }> {\n    return this.ok(message, {\n      data,\n      ...(meta && Object.keys(meta).length > 0 && { meta })\n    }, code);\n  }\n}\n","/**\n * @ author: richen\n * @ copyright: Copyright (c) - <richenlin(at)gmail.com>\n * @ license: BSD (3-Clause)\n * @ version: 2020-12-15 11:49:15\n */\n\nimport { IOCContainer } from \"koatty_container\";\nimport { Helper } from \"koatty_lib\";\nimport { DefaultLogger as Logger } from \"koatty_logger\";\nimport { Span, SpanStatusCode,  } from \"@opentelemetry/api\";\nimport { StatusCodeConvert } from \"./code\";\nimport { IExceptionContext } from \"./IContext\";\nimport { Output } from \"./output\";\nimport { ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_URL_FULL } from \"@opentelemetry/semantic-conventions\";\n\n/**\n * Exception configuration interface\n */\nexport interface ExceptionConfig {\n  enableStackTrace?: boolean;\n  logFormat?: 'json' | 'text';\n  customErrorFormat?: (error: Exception) => unknown;\n  maxStackLength?: number;\n}\n\n/**\n * Log data interface for text formatting\n */\ninterface LogData {\n  timestamp: string;\n  level: string;\n  type: string;\n  message: string;\n  code: number;\n  status: number;\n  context?: Partial<ErrorContext>;\n  stack?: string;\n}\n\n/**\n * Error context interface\n */\ninterface ErrorContext {\n  requestId: string;\n  url: string;\n  method: string;\n  userAgent?: string;\n  startTime: number;\n  endTime: number;\n  duration: number;\n  // 允许任意额外字段\n  [key: string]: unknown;\n}\n\n// 全局配置\nlet globalConfig: ExceptionConfig = {\n  enableStackTrace: process.env.NODE_ENV !== 'production',\n  logFormat: 'json',\n  maxStackLength: 1000\n};\n\n/**\n * Set global exception configuration\n * \n * @param {Partial<ExceptionConfig>} config - Configuration options\n */\nexport function setExceptionConfig(config: Partial<ExceptionConfig>): void {\n  globalConfig = { ...globalConfig, ...config };\n}\n\n/**\n * Get current exception configuration\n * \n * @returns {ExceptionConfig} Current configuration\n */\nexport function getExceptionConfig(): ExceptionConfig {\n  return { ...globalConfig };\n}\n\n/**\n * Indicates that an decorated class is a \"ExceptionHandler\".\n * @ExceptionHandler()\n * export class BusinessException extends Exception { \n *    constructor(message: string, code: number, status: number) { ... }\n *    handler(ctx: IExceptionContext) { \n * \n *      ...//Handling business exceptions \n * \n *    }\n * }\n *\n * @export\n * @param {string} [identifier] class name\n * @returns {ClassDecorator}\n */\nexport function ExceptionHandler(): ClassDecorator {\n  return (target: Function) => {\n    const identifier = IOCContainer.getIdentifier(target);\n    // if (identifier === \"Exception\") {\n    //     throw new Error(\"class name cannot be `Exception`\");\n    // }\n    // if (!identifier.endsWith(\"Exception\")) {\n    //     throw Error(\"class name must end with 'Exception'\");\n    // }\n    // if (!target.prototype.type) {\n    //     throw new Error(\"class's property 'type' must be set\");\n    // }\n    if (!(target.prototype instanceof Exception)) {\n      throw new Error(`class ${identifier} does not inherit from class 'Exception'`);\n    }\n    IOCContainer.saveClass(\"COMPONENT\", target, \"ExceptionHandler\");\n  };\n}\n\n/**\n * Predefined runtime exception\n *\n * @export\n * @class Exception\n * @extends {Error}\n */\nexport class Exception extends Error {\n  public readonly type: string = 'Exception';\n  public status: number = 500;\n  public code: number = 1;\n  public span?: Span;\n  public timestamp: number;\n  public context?: Partial<ErrorContext>;\n\n  /**\n   * @description: Creates an instance of Exception.\n   * @param {string} message err message\n   * @param {number} code err code\n   * @param {number} status http status\n   * @param {string} stack err stack\n   * @param {Span} span opentracing span\n   * @return {Exception}\n   */\n  constructor(message: string, code?: number, status?: number, stack?: string, span?: Span) {\n    super(message);\n    this.timestamp = Date.now();\n    this.setCode(code);\n    this.setStatus(status);\n    this.setStack(stack);\n    this.span = span;\n    \n    // 确保错误名称正确\n    this.name = this.constructor.name;\n  }\n\n  /**\n   * Set error code with validation\n   * \n   * @param {number} code - Error code\n   * @returns {Exception} This instance for chaining\n   */\n  setCode(code?: number): this {\n    if (code !== undefined && Helper.isNumber(code) && code >= 0) {\n      this.code = Math.floor(code); // 确保是整数\n    }\n    return this;\n  }\n\n  /**\n   * Set HTTP status with validation\n   * \n   * @param {number} status - HTTP status code\n   * @returns {Exception} This instance for chaining\n   */\n  setStatus(status?: number): this {\n    if (status !== undefined && Helper.isNumber(status) && status >= 100 && status < 600) {\n      this.status = Math.floor(status); // 确保是整数\n    }\n    return this;\n  }\n\n  /**\n   * Set error message with validation\n   * \n   * @param {string} message - Error message\n   * @returns {Exception} This instance for chaining\n   */\n  setMessage(message: string): this {\n    if (message && typeof message === 'string') {\n      this.message = message.trim();\n    }\n    return this;\n  }\n\n  /**\n   * Set stack trace with validation\n   * \n   * @param {string} stack - Stack trace\n   * @returns {Exception} This instance for chaining\n   */\n  setStack(stack?: string): this {\n    if (stack && typeof stack === 'string') {\n      const config = getExceptionConfig();\n      this.stack = config.maxStackLength && stack.length > config.maxStackLength \n        ? stack.substring(0, config.maxStackLength) + '...[truncated]'\n        : stack;\n    }\n    return this;\n  }\n\n  /**\n   * Set OpenTelemetry span\n   * \n   * @param {Span} span - OpenTelemetry span\n   * @returns {Exception} This instance for chaining\n   */\n  setSpan(span: Span): this {\n    if (span) {\n      this.span = span;\n    }\n    return this;\n  }\n\n  /**\n   * Set error context\n   * \n   * @param {Partial<ErrorContext>} context - Error context\n   * @returns {Exception} This instance for chaining\n   */\n  setContext(context: Partial<ErrorContext>): this {\n    this.context = { ...this.context, ...context };\n    return this;\n  }\n\n  /**\n   * @description: Default exception handler\n   * @param {IExceptionContext} ctx\n   * @return {Promise<unknown>}\n   */\n  async handler(ctx: IExceptionContext): Promise<unknown> {\n    try {\n      // 设置响应状态\n      ctx.status = this.status || ctx.status;\n\n      // 设置错误上下文\n      this.setContext({\n        requestId: ctx.requestId,\n        path: ctx.originalPath || '/',\n        method: ctx.method,\n        userAgent: ctx.get('User-Agent'),\n        startTime: ctx.startTime,\n        endTime: Date.now(),\n        duration: Date.now() - ctx.startTime\n      });\n\n      // 记录日志\n      this.log(ctx);\n\n      // 设置响应类型\n      ctx.type = ctx.encoding !== false ? `application/json; charset=${ctx.encoding}` : 'application/json';\n\n      return this.output(ctx);\n    } catch (error) {\n      Logger.Error('Exception handler failed:', error);\n\n      // 降级处理 - 返回基本错误响应\n      return this.fallbackOutput(ctx, error);\n    }\n  }\n\n  /**\n   * @description: 降级输出处理\n   * @param {IExceptionContext} ctx\n   * @param {unknown} _error\n   * @return {unknown}\n   */\n  private fallbackOutput(ctx: IExceptionContext, _error: unknown): unknown {\n    const isGrpc = ctx.protocol === 'grpc';\n    const isWebSocket = ctx.protocol === 'ws' || ctx.protocol === 'wss';\n\n    const fallbackResponse: { code: number; message: string; data: null } = {\n      code: 500,\n      message: \"Internal Server Error\",\n      data: null\n    };\n\n    if (isGrpc) {\n      return ctx.rpc.callback({\n        code: 13, // INTERNAL\n        details: JSON.stringify(fallbackResponse)\n      }, null);\n    }\n\n    const body = JSON.stringify(fallbackResponse);\n    ctx.length = Buffer.byteLength(body);\n\n    if (isWebSocket) {\n      return ctx.websocket.send(body);\n    }\n\n    return ctx.res.end(body);\n  }\n\n  /**\n   * @description: 结构化日志记录\n   * @param {IExceptionContext} ctx\n   * @return {void}\n   */\n  protected log(ctx: IExceptionContext): void {\n    const config = getExceptionConfig();\n    const logData = {\n      timestamp: new Date().toISOString(),\n      level: 'ERROR',\n      type: this.type,\n      message: this.message,\n      code: this.code,\n      status: this.status,\n      context: this.context || {\n        requestId: ctx.requestId,\n        path: ctx.originalPath || '/',\n        method: ctx.method,\n        startTime: ctx.startTime,\n        duration: Date.now() - ctx.startTime,\n        endTime: Date.now()\n      },\n      ...(config.enableStackTrace && this.stack && { stack: this.stack })\n    };\n\n    // 根据配置决定日志格式\n    const logMessage = config.logFormat === 'json' \n      ? JSON.stringify(logData, null, 2)\n      : this.formatTextLog(logData);\n\n    Logger.Error(logMessage);\n\n    // 更新链路追踪信息\n    this.updateSpan(ctx);\n  }\n\n  /**\n   * Format log as text\n   *\n   * @param {LogData} logData - Log data object\n   * @returns {string} Formatted text log\n   */\n  private formatTextLog(logData: LogData): string {\n    const { timestamp, level, type, message, code, status, context, stack } = logData;\n    let log = `[${timestamp}] ${level}: ${type} - ${message} (code: ${code}, status: ${status})`;\n\n    if (context) {\n      log += `\\n  Context: ${JSON.stringify(context)}`;\n    }\n\n    if (stack) {\n      log += `\\n  Stack: ${stack}`;\n    }\n\n    return log;\n  }\n\n  /**\n   * Update OpenTelemetry span with error information\n   * \n   * @param {IExceptionContext} ctx - Koatty context\n   */\n  private updateSpan(ctx: IExceptionContext): void {\n    if (this.span) {\n      this.span.setStatus({ \n        code: SpanStatusCode.ERROR, \n        message: this.message \n      });\n      this.span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, ctx.status);\n      this.span.setAttribute(ATTR_HTTP_REQUEST_METHOD, ctx.method);\n      this.span.setAttribute(ATTR_URL_FULL, ctx.url);\n      this.span.setAttribute('error.code', this.code);\n      this.span.setAttribute('error.type', this.type);\n    }\n  }\n\n  /**\n   * @description: 输出处理\n   * @param {IExceptionContext} ctx\n   * @return {unknown}\n   */\n  protected output(ctx: IExceptionContext): unknown {\n    const config = getExceptionConfig();\n    const isGrpc = ctx.protocol === 'grpc';\n    const isWebSocket = ctx.protocol === 'ws' || ctx.protocol === 'wss';\n\n    // 使用自定义格式或默认格式\n    const responseBody = config.customErrorFormat\n      ? config.customErrorFormat(this)\n      : this.message || \"\";\n\n    if (isGrpc) {\n      if (this.code < 2) {\n        this.code = StatusCodeConvert(ctx.status);\n      }\n      return ctx.rpc.callback({\n        code: this.code,\n        details: JSON.stringify(ctx.body || responseBody || this.message || \"Internal error\")\n      }, null);\n    }\n\n    // 防止 \"write after end\" 错误：检查响应是否已经结束\n    if (ctx.res && (ctx.res.writableEnded || ctx.res.finished)) {\n      Logger.Warn(`Response already ended for request ${ctx.requestId}, skipping output`);\n      return;\n    }\n\n    const body = JSON.stringify(Output.fail(responseBody, ctx.body || '', this.code));\n    ctx.length = Buffer.byteLength(body);\n\n    if (isWebSocket) {\n      return ctx.websocket.send(body);\n    }\n\n    return ctx.res.end(body);\n  }\n\n  /**\n   * Convert exception to plain object\n   * \n   * @returns {object} Plain object representation\n   */\n  toJSON(): object {\n    const config = getExceptionConfig();\n    return {\n      type: this.type,\n      name: this.name,\n      message: this.message,\n      code: this.code,\n      status: this.status,\n      timestamp: this.timestamp,\n      context: this.context,\n      ...(config.enableStackTrace && this.stack && { stack: this.stack })\n    };\n  }\n}\n\n","/*\n * @Description: \n * @Usage: \n * @Author: richen\n * @Date: 2022-02-10 17:40:55\n * @LastEditTime: 2024-02-01 10:48:46\n */\nimport * as Helper from \"koatty_lib\";\nimport { Exception } from \"./exception\";\n\nconst PREVENT_NEXT_PROCESS = 'PREVENT_NEXT_PROCESS';\n\n/**\n * Prevent next process\n *\n * @returns {Promise<never>}\n */\nexport function prevent(): Promise<never> {\n  return Promise.reject(new Error(PREVENT_NEXT_PROCESS));\n}\n\n/**\n * Check if the error is a predefined exception\n * \n * @param {unknown} err - The error to check\n * @returns {err is Exception} Type guard for Exception\n */\nexport const isException = (err: unknown): err is Exception => {\n  if (err instanceof Exception) {\n    return true;\n  }\n  \n  // 检查是否具有 Exception 的特征\n  return !!(\n    err && \n    typeof err === 'object' && \n    'type' in err && \n    (err as any).type === \"Exception\" &&\n    'message' in err &&\n    'code' in err &&\n    'status' in err\n  );\n};\n\n/**\n * Create a safe error object from unknown input\n * \n * @param {unknown} err - The error input\n * @returns {Error} Safe error object\n */\nexport function toSafeError(err: unknown): Error {\n  if (Helper.isError(err)) {\n    return err;\n  }\n  \n  if (isException(err)) {\n    return err;\n  }\n  \n  if (typeof err === 'string') {\n    return new Error(err);\n  }\n  \n  if (typeof err === 'number') {\n    return new Error(String(err));\n  }\n  \n  if (typeof err === 'boolean') {\n    return new Error(String(err));\n  }\n  \n  if (err && typeof err === 'object' && 'message' in err) {\n    return new Error(String((err as any).message));\n  }\n  \n  return new Error('Unknown error occurred');\n}\n\n/**\n * Check if an error is a network error\n * \n * @param {unknown} err - The error to check\n * @returns {boolean} True if it's a network error\n */\nexport function isNetworkError(err: unknown): boolean {\n  if (!Helper.isError(err)) {\n    return false;\n  }\n  \n  const networkErrorCodes = ['ECONNREFUSED', 'ENOTFOUND', 'ETIMEDOUT', 'ECONNRESET'];\n  return networkErrorCodes.includes((err as any).code);\n}\n\n","/**\n * @ author: richen\n * @ copyright: Copyright (c) - <richenlin(at)gmail.com>\n * @ license: BSD (3-Clause)\n * @ version: 2025-01-31\n */\n\nimport { Exception } from \"./exception\";\nimport { CommonErrorCode } from \"./code\";\nimport { isException, toSafeError } from \"./utils\";\n\n/**\n * Exception constructor type\n */\nexport type ExceptionConstructor<T extends Exception = Exception> = new (\n  message: string,\n  code?: number,\n  status?: number\n) => T;\n\n/**\n * Catch decorator options interface\n */\nexport interface CatchOptions<T extends Exception = Exception> {\n  /**\n   * Business error code\n   * @default 1 (CommonErrorCode.GENERAL_ERROR)\n   */\n  code?: number;\n\n  /**\n   * HTTP status code\n   * @default 500\n   */\n  status?: number;\n\n  /**\n   * Error message template\n   * - string: Fixed message\n   * - function: Dynamic message generator (err) => string\n   * @default Uses original error's message\n   */\n  message?: string | ((err: Error) => string);\n\n  /**\n   * Custom Exception class\n   * Caught errors will be converted to instances of this class\n   * @default Exception\n   */\n  exception?: ExceptionConstructor<T>;\n\n  /**\n   * Error types to catch\n   * - If specified, only catch these types of errors\n   * - Other error types will be re-thrown\n   * @default Catches all errors\n   */\n  catchTypes?: (new (...args: any[]) => Error)[];\n\n  /**\n   * Whether to suppress the error (for special scenarios)\n   * @default false - Converted exception will be thrown\n   */\n  suppress?: boolean;\n\n  /**\n   * Error transformation callback\n   * Process the exception before throwing\n   */\n  transform?: (exception: T, originalError: Error) => T;\n\n  /**\n   * Whether to preserve the original stack trace\n   * @default true\n   */\n  preserveStack?: boolean;\n}\n\n/**\n * Check if value is an Exception constructor\n */\nfunction isExceptionConstructor(\n  value: unknown\n): value is ExceptionConstructor {\n  return (\n    typeof value === 'function' &&\n    (value === Exception || value.prototype instanceof Exception)\n  );\n}\n\n/**\n * Check if error should be caught based on catchTypes\n */\nfunction shouldCatch(\n  error: Error,\n  catchTypes?: (new (...args: any[]) => Error)[]\n): boolean {\n  if (!catchTypes || catchTypes.length === 0) {\n    return true; // Catch all errors\n  }\n  return catchTypes.some(ErrorType => error instanceof ErrorType);\n}\n\n/**\n * Parse decorator arguments into CatchOptions\n */\nfunction parseOptions<T extends Exception>(\n  args: unknown[]\n): CatchOptions<T> {\n  if (args.length === 0) {\n    return {};\n  }\n\n  const first = args[0];\n\n  // @Catch(ExceptionClass)\n  if (isExceptionConstructor(first)) {\n    return { exception: first as ExceptionConstructor<T> };\n  }\n\n  // @Catch(code, message?)\n  if (typeof first === 'number') {\n    return {\n      code: first,\n      message: typeof args[1] === 'string' ? args[1] : undefined,\n    };\n  }\n\n  // @Catch([ErrorType1, ErrorType2], options?)\n  if (Array.isArray(first)) {\n    const errorTypes = first as (new (...args: any[]) => Error)[];\n    const options = (args[1] as Omit<CatchOptions<T>, 'catchTypes'>) ?? {};\n    return {\n      ...options,\n      catchTypes: errorTypes,\n    };\n  }\n\n  // @Catch({ ... })\n  if (typeof first === 'object' && first !== null) {\n    return first as CatchOptions<T>;\n  }\n\n  return {};\n}\n\n/**\n * Method decorator: Actively catch errors during method execution and convert to Exception\n * \n * @description\n * This decorator wraps the method in a try-catch block and converts caught errors\n * to Exception instances. It supports multiple calling conventions for flexibility.\n * \n * @overload No parameters, use default configuration\n * @example\n * ```typescript\n * @Catch()\n * async findUser(id: string) { ... }\n * ```\n * \n * @overload Pass configuration object\n * @example\n * ```typescript\n * @Catch({ code: 1001, status: 400, message: 'User query failed' })\n * async findUser(id: string) { ... }\n * ```\n * \n * @overload Pass Exception class (shorthand)\n * @example\n * ```typescript\n * @Catch(ValidationException)\n * async createUser(data: UserDTO) { ... }\n * ```\n * \n * @overload Pass error code and message (shorthand)\n * @example\n * ```typescript\n * @Catch(1001, 'Operation failed')\n * async deleteUser(id: string) { ... }\n * ```\n * \n * @overload Catch specific error types only\n * @example\n * ```typescript\n * @Catch([TypeError, RangeError], { code: 3001, message: 'Type error' })\n * async processData(data: unknown) { ... }\n * ```\n */\nexport function Catch(): MethodDecorator;\nexport function Catch<T extends Exception>(\n  exception: ExceptionConstructor<T>\n): MethodDecorator;\nexport function Catch(code: number, message?: string): MethodDecorator;\nexport function Catch<T extends Exception>(\n  options: CatchOptions<T>\n): MethodDecorator;\nexport function Catch<T extends Exception>(\n  errorTypes: (new (...args: any[]) => Error)[],\n  options?: Omit<CatchOptions<T>, 'catchTypes'>\n): MethodDecorator;\nexport function Catch<T extends Exception = Exception>(\n  ...args: unknown[]\n): MethodDecorator {\n  const options = parseOptions<T>(args);\n\n  return function (\n    target: object,\n    propertyKey: string | symbol,\n    descriptor: TypedPropertyDescriptor<any>\n  ): TypedPropertyDescriptor<any> {\n    const originalMethod = descriptor.value;\n\n    if (typeof originalMethod !== 'function') {\n      throw new Error(\n        `@Catch() can only be applied to methods, but \"${String(propertyKey)}\" is not a function`\n      );\n    }\n\n    descriptor.value = async function (\n      this: unknown,\n      ...methodArgs: unknown[]\n    ): Promise<unknown> {\n      try {\n        const result = originalMethod.apply(this, methodArgs);\n        // Handle both Promise and regular return values\n        if (result instanceof Promise) {\n          return await result;\n        }\n        return result;\n      } catch (err) {\n        const safeError = toSafeError(err);\n\n        // Check if this type of error should be caught\n        if (!shouldCatch(safeError, options.catchTypes)) {\n          throw err; // Don't catch, re-throw\n        }\n\n        // If already an Exception and no new options specified, preserve it\n        if (\n          isException(err) &&\n          !options.exception &&\n          options.code === undefined &&\n          options.message === undefined &&\n          options.status === undefined\n        ) {\n          throw err;\n        }\n\n        // Construct new Exception\n        const ExceptionClass = options.exception ?? Exception;\n\n        // Parse error message\n        let errorMessage: string;\n        if (typeof options.message === 'function') {\n          errorMessage = options.message(safeError);\n        } else if (typeof options.message === 'string') {\n          errorMessage = options.message;\n        } else {\n          errorMessage = safeError.message;\n        }\n\n        // Determine if we should use custom Exception's defaults\n        // When only exception class is specified without code/status,\n        // let the custom Exception class use its own default values\n        const useCustomDefaults =\n          options.exception !== undefined &&\n          options.code === undefined &&\n          options.status === undefined;\n\n        // Parse error code (prefer config, fallback to original error's code or undefined for custom defaults)\n        const errorCode = useCustomDefaults\n          ? undefined\n          : options.code ??\n            (isException(err) ? err.code : CommonErrorCode.GENERAL_ERROR);\n\n        // Parse status code\n        const errorStatus = useCustomDefaults\n          ? undefined\n          : options.status ?? (isException(err) ? err.status : 500);\n\n        // Create new Exception instance\n        const exception = new ExceptionClass(\n          errorMessage,\n          errorCode,\n          errorStatus\n        );\n\n        // Preserve original stack trace (if configured)\n        if (options.preserveStack !== false && safeError.stack) {\n          exception.setStack(safeError.stack);\n        }\n\n        // Apply transform function\n        const finalException = options.transform\n          ? options.transform(exception as T, safeError)\n          : exception;\n\n        // If suppress is true, don't throw (for special scenarios)\n        if (options.suppress) {\n          return undefined;\n        }\n\n        throw finalException;\n      }\n    };\n\n    // Preserve original method metadata\n    Object.defineProperty(descriptor.value, 'name', {\n      value: originalMethod.name,\n      configurable: true,\n    });\n\n    // Copy any existing metadata from the original method\n    if (originalMethod.length !== undefined) {\n      Object.defineProperty(descriptor.value, 'length', {\n        value: originalMethod.length,\n        configurable: true,\n      });\n    }\n\n    return descriptor;\n  };\n}\n\n"]}