@saihu/common 1.1.93 → 1.1.94

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.
@@ -6,6 +6,11 @@ export declare class UnifiedExceptionFilter implements ExceptionFilter {
6
6
  catch(exception: any, host: ArgumentsHost): void;
7
7
  private mapAppErrorCodeToHttpStatus;
8
8
  private logError;
9
+ /**
10
+ * Determine if an error is "expected" (business logic, validation)
11
+ * vs "unexpected" (infrastructure failures, bugs)
12
+ */
13
+ private isExpectedError;
9
14
  /**
10
15
  * Recursively sanitize sensitive information from details object
11
16
  * Handles nested objects like { headers: { authorization: "..." } }
@@ -1 +1 @@
1
- {"version":3,"file":"unified-exception.filter.d.ts","sourceRoot":"","sources":["../../src/errors/unified-exception.filter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAEf,aAAa,EAGd,MAAM,gBAAgB,CAAC;AAOxB,qBACa,sBAAuB,YAAW,eAAe;IAC5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2C;IAElE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAM7B;IACF,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAQ;IAE3C,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa;IA+CzC,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,QAAQ;IA2BhB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAUvB;;OAEG;IACH,OAAO,CAAC,cAAc;IAmCtB;;;OAGG;IACH,OAAO,CAAC,cAAc;CAQvB"}
1
+ {"version":3,"file":"unified-exception.filter.d.ts","sourceRoot":"","sources":["../../src/errors/unified-exception.filter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAEf,aAAa,EAGd,MAAM,gBAAgB,CAAC;AAOxB,qBACa,sBAAuB,YAAW,eAAe;IAC5D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2C;IAElE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAM7B;IACF,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAQ;IAE3C,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa;IA+CzC,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,QAAQ;IAiChB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAoBvB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAUvB;;OAEG;IACH,OAAO,CAAC,cAAc;IAmCtB;;;OAGG;IACH,OAAO,CAAC,cAAc;CAQvB"}
@@ -91,9 +91,36 @@ let UnifiedExceptionFilter = UnifiedExceptionFilter_1 = class UnifiedExceptionFi
91
91
  ]
92
92
  .filter(Boolean)
93
93
  .join(' | ');
94
- this.logger.error(logMessage, exception.stack);
95
- if (cause === null || cause === void 0 ? void 0 : cause.stack)
96
- this.logger.error(`Caused by: ${cause.stack}`);
94
+ // Expected errors (business/validation) → warn, no stack
95
+ // Unexpected errors (infra/unknown) error with stack
96
+ if (this.isExpectedError(exception, code)) {
97
+ this.logger.warn(logMessage);
98
+ }
99
+ else {
100
+ this.logger.error(logMessage, exception.stack);
101
+ if (cause === null || cause === void 0 ? void 0 : cause.stack)
102
+ this.logger.error(`Caused by: ${cause.stack}`);
103
+ }
104
+ }
105
+ /**
106
+ * Determine if an error is "expected" (business logic, validation)
107
+ * vs "unexpected" (infrastructure failures, bugs)
108
+ */
109
+ isExpectedError(exception, code) {
110
+ // Domain errors are always expected (business rule violations)
111
+ if (exception instanceof domain_error_1.DomainError)
112
+ return true;
113
+ // Application errors with these codes are expected
114
+ const expectedCodes = [
115
+ application_error_1.ErrorCodes.RESOURCE_NOT_FOUND,
116
+ application_error_1.ErrorCodes.INVALID_INPUT,
117
+ ];
118
+ if (exception instanceof application_error_1.ApplicationError &&
119
+ expectedCodes.includes(code)) {
120
+ return true;
121
+ }
122
+ // Infrastructure errors and unknown errors are unexpected
123
+ return false;
97
124
  }
98
125
  /**
99
126
  * Recursively sanitize sensitive information from details object
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saihu/common",
3
- "version": "1.1.93",
3
+ "version": "1.1.94",
4
4
  "description": "Common utilities for NestJS applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",