-
-
Notifications
You must be signed in to change notification settings - Fork 447
patch: 1.4.22 #1657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
patch: 1.4.22 #1657
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,43 @@ | ||
| import { Elysia, t } from '../src' | ||
| import { z } from 'zod' | ||
| import { req } from '../test/utils' | ||
|
|
||
| export const app = new Elysia() | ||
| .ws('/', { | ||
| open(ws) { | ||
| ws.subscribe('a') | ||
| }, | ||
| message(a) { | ||
| console.log(a.subscriptions) | ||
| } | ||
| }) | ||
| .listen(3000) | ||
|
|
||
| export const errorHandler = new Elysia({ name: "error-handler" }) | ||
| .onError(({ code, error, status }) => { | ||
| switch (code) { | ||
| case "VALIDATION": { | ||
| const allErrors = error.detail | ||
|
|
||
| return status(422, { | ||
| status: 422, | ||
| message: error.valueError?.message, | ||
| details: { | ||
| location: error.type, | ||
| rejected_value: error.value, | ||
| expected: error.expected, | ||
| }, | ||
| }) | ||
| } | ||
| case "NOT_FOUND": { | ||
| return status(404, { | ||
| status: 404, | ||
| message: "Route not found", | ||
| }) | ||
| } | ||
| default: { | ||
| const statusCode = | ||
| "status" in error | ||
| ? (typeof error.status === "number" ? error.status : Number(error.status)) || 500 | ||
| : 500 | ||
|
|
||
| let errMsg = "An error occurred" | ||
| if (error instanceof Error && error.message) { | ||
| errMsg = error.message | ||
| } | ||
|
|
||
| return status(statusCode, { | ||
| status: statusCode, | ||
| message: errMsg, | ||
| }) | ||
| } | ||
| } | ||
| }) | ||
| .as("scoped") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,9 @@ type CheckExcessProps<T, U> = 0 extends 1 & T | |
| : U extends U | ||
| ? Exclude<keyof T, keyof U> extends never | ||
| ? T | ||
| : { [K in keyof U]: U[K] } & { [K in Exclude<keyof T, keyof U>]: never } | ||
| : { [K in keyof U]: U[K] } & { | ||
| [K in Exclude<keyof T, keyof U>]: never | ||
| } | ||
| : never | ||
|
|
||
| export type SelectiveStatus<in out Res> = < | ||
|
|
@@ -154,27 +156,14 @@ export class InvalidCookieSignature extends Error { | |
| } | ||
| } | ||
|
|
||
| type MapValueError = | ||
| | { | ||
| summary: undefined | ||
| } | ||
| | { | ||
| summary: string | ||
| } | ||
| | Prettify< | ||
| { | ||
| summary: string | ||
| } & ValueError | ||
| > | ||
|
|
||
| export const mapValueError = (error: ValueError | undefined): MapValueError => { | ||
| if (!error) | ||
| return { | ||
| summary: undefined | ||
| } | ||
| interface ValueErrorWithSummary extends ValueError { | ||
| summary?: string | ||
| } | ||
|
|
||
| let { message, path, value, type } = error | ||
| export const mapValueError = (error: ValueError): ValueErrorWithSummary => { | ||
| if (!error) return error | ||
|
|
||
| let { message, path, value, type } = error | ||
|
Comment on lines
+163
to
+166
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type signature inconsistency with runtime guard. The parameter is typed as Consider either:
🔎 Option 1: Reflect nullable types-export const mapValueError = (error: ValueError): ValueErrorWithSummary => {
- if (!error) return error
+export const mapValueError = (error: ValueError | undefined): ValueErrorWithSummary | undefined => {
+ if (!error) return undefined🤖 Prompt for AI Agents |
||
| if (Array.isArray(path)) path = path[0] | ||
|
|
||
| const property = | ||
|
|
@@ -495,7 +484,7 @@ export class ValidationError extends Error { | |
| Object.setPrototypeOf(this, ValidationError.prototype) | ||
| } | ||
|
|
||
| get all(): MapValueError[] { | ||
| get all(): ValueErrorWithSummary[] { | ||
| // Handle standard schema validators (Zod, Valibot, etc.) | ||
| if ( | ||
| // @ts-ignore | ||
|
|
@@ -607,7 +596,9 @@ export class ValidationError extends Error { | |
| on: this.type, | ||
| property: this.valueError?.path || 'root', | ||
| message, | ||
| summary: mapValueError(this.valueError).summary, | ||
| summary: this.valueError | ||
| ? mapValueError(this.valueError).summary | ||
| : undefined, | ||
| found: value, | ||
| expected, | ||
| errors | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error.detailis a method, not a property—andallErrorsis unused.detail()inValidationErroris a method requiring parameters (message,allowUnsafeValidatorDetails). Line 7 assigns the method reference itself (not its result) toallErrors, and the variable is never used.Either remove the dead code or call the method properly:
🔎 Option 1: Remove unused code
case "VALIDATION": { - const allErrors = error.detail - return status(422, {🔎 Option 2: If you intended to get all errors
case "VALIDATION": { - const allErrors = error.detail + const allErrors = error.all // Use the getter for all validation errors return status(422, { status: 422, message: error.valueError?.message, details: { location: error.type, rejected_value: error.value, expected: error.expected, + errors: allErrors, }, }) }📝 Committable suggestion
🤖 Prompt for AI Agents