@teardown/errors 0.1.48 → 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.48",
3
+ "version": "0.1.49",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -18,6 +18,11 @@
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": {
@@ -31,14 +36,17 @@
31
36
  },
32
37
  "devDependencies": {
33
38
  "@biomejs/biome": "2.3.8",
34
- "@teardown/tsconfig": "0.1.47",
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.19"
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.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,
@@ -201,7 +200,7 @@ const handleZodError = (error: ZodError): ErrorHandlerResult => {
201
200
  export function handleError(error: unknown, code: number | string = 500): ErrorHandlerResult {
202
201
  // Handle Elysia ValidationError (duck-typed check)
203
202
  if (code === "VALIDATION" || (error && typeof error === "object" && "type" in error && error.type === "validation")) {
204
- return handleValidationError(error as ValidationError);
203
+ return handleValidationError(error);
205
204
  }
206
205
 
207
206
  // Handle ZodError (duck-typed check for issues array)
@@ -266,36 +265,3 @@ export function handleError(error: unknown, code: number | string = 500): ErrorH
266
265
  },
267
266
  };
268
267
  }
269
-
270
- export const ElysiaErrors = new Elysia()
271
- .error({
272
- FORBIDDEN: ForbiddenError,
273
- NOT_FOUND: NotFoundError,
274
- INTERNAL_SERVER_ERROR: InternalServerError,
275
- BAD_REQUEST: BadRequestError,
276
- UNAUTHORIZED: UnauthorizedError,
277
- UNPROCESSABLE_ENTITY: UnprocessableContentError,
278
- TOO_MANY_REQUESTS: RateLimitError,
279
- SERVICE_UNAVAILABLE: InternalServerError,
280
- })
281
- .onError(({ error, code, set }) => {
282
- // Skip logging validation errors - they're expected and properly handled by Elysia
283
- if (error instanceof ValidationError || code === "VALIDATION") {
284
- const result = handleError(error, code);
285
- set.status = result.status;
286
- return result.body;
287
- }
288
-
289
- console.error("[ErrorHandler] Unhandled error:", {
290
- code,
291
- error,
292
- errorType: typeof error,
293
- errorConstructor: error?.constructor?.name,
294
- errorMessage: error instanceof Error ? error.message : String(error),
295
- errorStack: error instanceof Error ? error.stack : undefined,
296
- });
297
- const result = handleError(error, code);
298
- set.status = result.status;
299
- return result.body;
300
- })
301
- .as("global");