@asapjs/error 1.0.0-alpha.18 → 1.0.0-alpha.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/helpers.d.ts CHANGED
@@ -2,6 +2,8 @@ import { Effect, Cause } from 'effect';
2
2
  import { Response } from 'express';
3
3
  import { HttpErrorBody } from './types';
4
4
  export declare function makeHttpError(status: number, errorCode: string, message: string, data?: Record<string, any>): HttpErrorBody;
5
+ /** 프레임워크 독립 — 에러를 HttpErrorBody로 정규화 */
6
+ export declare function resolveErrorBody(error: unknown): HttpErrorBody;
5
7
  export declare function errorToResponse(error: unknown, res: Response): void;
6
8
  export declare function causeToError(cause: Cause.Cause<unknown>): unknown;
7
9
  export declare function runEffectAsPromise<A, E>(effect: Effect.Effect<A, E, never>): Promise<A>;
package/dist/helpers.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeHttpError = makeHttpError;
4
+ exports.resolveErrorBody = resolveErrorBody;
4
5
  exports.errorToResponse = errorToResponse;
5
6
  exports.causeToError = causeToError;
6
7
  exports.runEffectAsPromise = runEffectAsPromise;
@@ -14,25 +15,26 @@ function makeHttpError(status, errorCode, message, data) {
14
15
  data,
15
16
  };
16
17
  }
17
- function errorToResponse(error, res) {
18
- let errorBody;
18
+ /** 프레임워크 독립 — 에러를 HttpErrorBody로 정규화 */
19
+ function resolveErrorBody(error) {
19
20
  if (error instanceof types_1.HttpError) {
20
- errorBody = error.toJSON();
21
+ return error.toJSON();
21
22
  }
22
- else if (error && typeof error === 'object' && 'status' in error && 'message' in error && !('errorCode' in error)) {
23
+ if (error && typeof error === 'object' && 'status' in error && 'message' in error && !('errorCode' in error)) {
23
24
  // Legacy HttpException 지원
24
- errorBody = {
25
+ return {
25
26
  status: error.status,
26
27
  errorCode: 'LEGACY_HTTP_EXCEPTION',
27
28
  message: error.message,
28
29
  };
29
30
  }
30
- else if (error && typeof error === 'object' && 'status' in error && 'errorCode' in error && 'message' in error) {
31
- errorBody = error;
32
- }
33
- else {
34
- errorBody = new types_1.HttpError(500, 'INTERNAL_SERVER_ERROR', error instanceof Error ? error.message : '알 수 없는 서버 오류가 발생했습니다.').toJSON();
31
+ if (error && typeof error === 'object' && 'status' in error && 'errorCode' in error && 'message' in error) {
32
+ return error;
35
33
  }
34
+ return new types_1.HttpError(500, 'INTERNAL_SERVER_ERROR', error instanceof Error ? error.message : '알 수 없는 서버 오류가 발생했습니다.').toJSON();
35
+ }
36
+ function errorToResponse(error, res) {
37
+ const errorBody = resolveErrorBody(error);
36
38
  res.status(errorBody.status).json(errorBody);
37
39
  }
38
40
  function causeToError(cause) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asapjs/error",
3
- "version": "1.0.0-alpha.18",
3
+ "version": "1.0.0-alpha.28",
4
4
  "description": "Error handling utilities for ASAP.js with Effect integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,9 +12,9 @@
12
12
  "dev": "tsc --watch"
13
13
  },
14
14
  "dependencies": {
15
- "@asapjs/common": "^1.0.0-alpha.13",
15
+ "@asapjs/common": "^1.0.0-alpha.28",
16
16
  "@asapjs/schema": "^1.0.0-alpha.18",
17
- "@asapjs/types": "^1.0.0-alpha.11",
17
+ "@asapjs/types": "^1.0.0-alpha.28",
18
18
  "effect": "^3.11.11",
19
19
  "express": "^4.20.0"
20
20
  },
@@ -29,5 +29,5 @@
29
29
  "publishConfig": {
30
30
  "access": "public"
31
31
  },
32
- "gitHead": "714c1603ca5182e805cfb2075c8c8d97f9ae7319"
32
+ "gitHead": "9c2b3ea910e8e1a4f26b9b20aa492a5a5e574d7d"
33
33
  }