@teardown/errors 0.1.46 → 0.1.49

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teardown/errors",
3
- "version": "0.1.46",
3
+ "version": "0.1.49",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -18,12 +18,17 @@
18
18
  "import": "./src/index.ts",
19
19
  "default": "./src/index.ts"
20
20
  },
21
+ "./elysia": {
22
+ "types": "./src/elysia.ts",
23
+ "import": "./src/elysia.ts",
24
+ "default": "./src/elysia.ts"
25
+ },
21
26
  "./package.json": "./package.json"
22
27
  },
23
28
  "scripts": {
24
- "build": "tsc --project ./tsconfig.lib.json",
25
- "dev": "tsc --watch --project ./tsconfig.lib.json",
26
- "typecheck": "tsc --noEmit --project ./tsconfig.lib.json",
29
+ "build": "bun x tsgo --project ./tsconfig.lib.json",
30
+ "dev": "bun x tsgo --watch --project ./tsconfig.lib.json",
31
+ "typecheck": "bun x tsgo --noEmit --project ./tsconfig.lib.json",
27
32
  "fmt": "bun x biome format --write ./src",
28
33
  "lint": "bun x biome lint --write ./src",
29
34
  "check": "bun x biome check ./src",
@@ -31,14 +36,17 @@
31
36
  },
32
37
  "devDependencies": {
33
38
  "@biomejs/biome": "2.3.8",
34
- "@teardown/tsconfig": "0.1.46",
39
+ "@teardown/tsconfig": "0.1.49",
35
40
  "@types/bun": "1.3.4"
36
41
  },
37
42
  "peerDependencies": {
43
+ "elysia": "1.4.19",
38
44
  "typescript": "5.9.3",
39
45
  "zod": "4.1.13"
40
46
  },
41
- "dependencies": {
42
- "elysia": "1.4.17"
47
+ "peerDependenciesMeta": {
48
+ "elysia": {
49
+ "optional": true
50
+ }
43
51
  }
44
52
  }
package/src/elysia.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { Elysia, ValidationError } from "elysia";
2
+ import {
3
+ BadRequestError,
4
+ ForbiddenError,
5
+ InternalServerError,
6
+ NotFoundError,
7
+ RateLimitError,
8
+ UnauthorizedError,
9
+ UnprocessableContentError,
10
+ handleError,
11
+ } from "./index";
12
+
13
+ export const ElysiaErrors = new Elysia()
14
+ .error({
15
+ FORBIDDEN: ForbiddenError,
16
+ NOT_FOUND: NotFoundError,
17
+ INTERNAL_SERVER_ERROR: InternalServerError,
18
+ BAD_REQUEST: BadRequestError,
19
+ UNAUTHORIZED: UnauthorizedError,
20
+ UNPROCESSABLE_ENTITY: UnprocessableContentError,
21
+ TOO_MANY_REQUESTS: RateLimitError,
22
+ SERVICE_UNAVAILABLE: InternalServerError,
23
+ })
24
+ .onError(({ error, code, set }) => {
25
+ // Skip logging validation errors - they're expected and properly handled by Elysia
26
+ if (error instanceof ValidationError || code === "VALIDATION") {
27
+ const result = handleError(error, code);
28
+ set.status = result.status;
29
+ return result.body;
30
+ }
31
+
32
+ console.error("[ErrorHandler] Unhandled error:", {
33
+ code,
34
+ error,
35
+ errorType: typeof error,
36
+ errorConstructor: error?.constructor?.name,
37
+ errorMessage: error instanceof Error ? error.message : String(error),
38
+ errorStack: error instanceof Error ? error.stack : undefined,
39
+ });
40
+ const result = handleError(error, code);
41
+ set.status = result.status;
42
+ return result.body;
43
+ })
44
+ .as("global");
package/src/index.test.ts CHANGED
@@ -127,4 +127,3 @@ describe("Errors", () => {
127
127
  });
128
128
  });
129
129
  });
130
-
package/src/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { Elysia, ValidationError } from "elysia";
2
1
  import { ZodError } from "zod";
3
2
 
4
3
  export enum ErrorCodes {
@@ -162,7 +161,7 @@ export interface ErrorHandlerResult {
162
161
  body: ErrorResponse;
163
162
  }
164
163
 
165
- const handleValidationError = (error: ValidationError): ErrorHandlerResult => {
164
+ const handleValidationError = (error: unknown): ErrorHandlerResult => {
166
165
  const message = error instanceof Error ? error.message : "Validation failed";
167
166
  return {
168
167
  status: 422,
@@ -197,10 +196,11 @@ const handleZodError = (error: ZodError): ErrorHandlerResult => {
197
196
  };
198
197
  };
199
198
 
199
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Complex error handling logic that requires multiple conditional branches
200
200
  export function handleError(error: unknown, code: number | string = 500): ErrorHandlerResult {
201
201
  // Handle Elysia ValidationError (duck-typed check)
202
202
  if (code === "VALIDATION" || (error && typeof error === "object" && "type" in error && error.type === "validation")) {
203
- return handleValidationError(error as ValidationError);
203
+ return handleValidationError(error);
204
204
  }
205
205
 
206
206
  // Handle ZodError (duck-typed check for issues array)
@@ -265,36 +265,3 @@ export function handleError(error: unknown, code: number | string = 500): ErrorH
265
265
  },
266
266
  };
267
267
  }
268
-
269
- export const ElysiaErrors = new Elysia()
270
- .error({
271
- FORBIDDEN: ForbiddenError,
272
- NOT_FOUND: NotFoundError,
273
- INTERNAL_SERVER_ERROR: InternalServerError,
274
- BAD_REQUEST: BadRequestError,
275
- UNAUTHORIZED: UnauthorizedError,
276
- UNPROCESSABLE_ENTITY: UnprocessableContentError,
277
- TOO_MANY_REQUESTS: RateLimitError,
278
- SERVICE_UNAVAILABLE: InternalServerError,
279
- })
280
- .onError(({ error, code, set }) => {
281
- // Skip logging validation errors - they're expected and properly handled by Elysia
282
- if (error instanceof ValidationError || code === "VALIDATION") {
283
- const result = handleError(error, code);
284
- set.status = result.status;
285
- return result.body;
286
- }
287
-
288
- console.error("[ErrorHandler] Unhandled error:", {
289
- code,
290
- error,
291
- errorType: typeof error,
292
- errorConstructor: error?.constructor?.name,
293
- errorMessage: error instanceof Error ? error.message : String(error),
294
- errorStack: error instanceof Error ? error.stack : undefined,
295
- });
296
- const result = handleError(error, code);
297
- set.status = result.status;
298
- return result.body;
299
- })
300
- .as("global");