From ccb95ed514f11630936d2cc57c50c9c47a393b93 Mon Sep 17 00:00:00 2001 From: RAUNAK <122172696+aunak@users.noreply.github.com> Date: Thu, 15 Jan 2026 02:10:53 +0530 Subject: [PATCH 1/2] fix(error): return 500 for response validation errors (#1480) Response validation errors now correctly return HTTP 500 (Internal Server Error) instead of 422 (Unprocessable Entity). This change distinguishes between: - Request validation errors (422): Client sent invalid data (query, body, headers, params, cookie) - client's fault - Response validation errors (500): Server returned data that doesn't match its own schema - server's bug The fix modifies ValidationError class in src/error.ts to: 1. Use dynamic status based on validation type 2. Set status = 500 when type === 'response', otherwise 422 3. Update toResponse() to use this.status This is a breaking change for APIs that relied on 422 for response validation errors, but it's the semantically correct behavior. Closes #1480 --- src/error.ts | 16 +- test/core/as.test.ts | 15 +- test/core/dynamic.test.ts | 16 +- test/core/handle-error.test.ts | 3 +- test/core/normalize.test.ts | 9 +- test/extends/error.test.ts | 3 +- test/extends/models.test.ts | 6 +- test/path/group.test.ts | 3 +- test/path/guard.test.ts | 24 ++- test/standard-schema/reference.test.ts | 6 +- test/standard-schema/standalone.test.ts | 9 +- test/standard-schema/validate.test.ts | 6 +- test/validator/novalidate.test.ts | 9 +- test/validator/response.test.ts | 202 +++++++++++++++++++++++- test/validator/standalone.test.ts | 20 ++- test/validator/validator.test.ts | 9 +- 16 files changed, 304 insertions(+), 52 deletions(-) diff --git a/src/error.ts b/src/error.ts index cdedf025..79ad6645 100644 --- a/src/error.ts +++ b/src/error.ts @@ -284,7 +284,15 @@ export class InvalidFileType extends Error { export class ValidationError extends Error { code = 'VALIDATION' - status = 422 + /** + * HTTP status code for this validation error. + * + * - Response validation errors (type === 'response') return 500 (Internal Server Error) + * because they indicate a server-side bug where the response doesn't match the schema. + * - Request validation errors (query, body, headers, params, cookie) return 422 (Unprocessable Entity) + * because they indicate client sent invalid data. + */ + status: number /** * An actual value of `message` @@ -481,6 +489,10 @@ export class ValidationError extends Error { this.expected = expected this.customError = customError + // Response validation errors are server bugs (500), not client errors (422) + // If the server returns data that doesn't match its own schema, that's an internal error + this.status = type === 'response' ? 500 : 422 + Object.setPrototypeOf(this, ValidationError.prototype) } @@ -546,7 +558,7 @@ export class ValidationError extends Error { toResponse(headers?: Record) { return new Response(this.message, { - status: 400, + status: this.status, headers: { ...headers, 'content-type': 'application/json' diff --git a/test/core/as.test.ts b/test/core/as.test.ts index 6c3352cb..44000e7c 100644 --- a/test/core/as.test.ts +++ b/test/core/as.test.ts @@ -104,7 +104,8 @@ describe('as', () => { ]) expect(called).toBe(3) - expect(response).toEqual([422, 422, 422]) + // Response validation errors return 500 (server error) - see issue rgba(23, 73, 137, 0) + expect(response).toEqual([500, 500, 500]) }) it('handle as global with local override', async () => { @@ -141,7 +142,8 @@ describe('as', () => { ]) expect(called).toBe(4) - expect(response).toEqual([422, 200, 422]) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response).toEqual([500, 200, 500]) }) it('handle as global with scoped override', async () => { @@ -178,7 +180,8 @@ describe('as', () => { ]) expect(called).toBe(5) - expect(response).toEqual([422, 200, 200]) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response).toEqual([500, 200, 200]) }) it('handle as scoped', async () => { @@ -209,7 +212,8 @@ describe('as', () => { ]) expect(called).toBe(2) - expect(response).toEqual([422, 422, 200]) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response).toEqual([500, 500, 200]) }) it('handle as scoped twice', async () => { @@ -242,6 +246,7 @@ describe('as', () => { ]) expect(called).toBe(3) - expect(response).toEqual([422, 422, 422]) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response).toEqual([500, 500, 500]) }) }) diff --git a/test/core/dynamic.test.ts b/test/core/dynamic.test.ts index 8cf39568..f2e3aaf0 100644 --- a/test/core/dynamic.test.ts +++ b/test/core/dynamic.test.ts @@ -529,8 +529,9 @@ describe('Dynamic Mode', () => { .handle(req('/valid-201')) .then((x) => x.status) - expect(invalid).toBe(422) - expect(invalid201).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(invalid).toBe(500) + expect(invalid201).toBe(500) expect(valid).toBe(200) expect(valid201).toBe(201) }) @@ -552,7 +553,8 @@ describe('Dynamic Mode', () => { const invalid = await app.handle(req('/invalid')).then((x) => x.status) const valid = await app.handle(req('/valid')).then((x) => x.json()) - expect(invalid).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(invalid).toBe(500) expect(valid).toEqual({ foo: 'bar' }) @@ -608,8 +610,9 @@ describe('Dynamic Mode', () => { .handle(req('/valid-201')) .then((x) => x.status) - expect(invalid).toBe(422) - expect(invalid201).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(invalid).toBe(500) + expect(invalid201).toBe(500) expect(valid).toBe(200) expect(valid201).toBe(201) }) @@ -634,7 +637,8 @@ describe('Dynamic Mode', () => { const invalid = await app.handle(req('/invalid')).then((x) => x.status) const valid = await app.handle(req('/valid')).then((x) => x.json()) - expect(invalid).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(invalid).toBe(500) expect(valid).toEqual({ foo: 'bar' }) diff --git a/test/core/handle-error.test.ts b/test/core/handle-error.test.ts index 00570f35..d7dc4073 100644 --- a/test/core/handle-error.test.ts +++ b/test/core/handle-error.test.ts @@ -572,7 +572,8 @@ describe('Handle Error', () => { const res = await app.handle(req('/')) - expect(res.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(res.status).toBe(500) expect(res.headers.get('set-cookie')).toContain('session=test-session-id') }) diff --git a/test/core/normalize.test.ts b/test/core/normalize.test.ts index c4355690..5c9c7abd 100644 --- a/test/core/normalize.test.ts +++ b/test/core/normalize.test.ts @@ -69,7 +69,8 @@ describe('Normalize', () => { const response = await app.handle(req('/')) - expect(response.status).toEqual(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response.status).toEqual(500) }) it('normalize multiple response', async () => { @@ -117,7 +118,8 @@ describe('Normalize', () => { const response = await app.handle(req('/')) - expect(response.status).toEqual(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response.status).toEqual(500) }) it('normalize multiple response using 200', async () => { @@ -171,7 +173,8 @@ describe('Normalize', () => { const response = await app.handle(req('/')) - expect(response.status).toEqual(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response.status).toEqual(500) }) it('do not normalize response when allowing additional properties', async () => { diff --git a/test/extends/error.test.ts b/test/extends/error.test.ts index f6af7607..593cbb79 100644 --- a/test/extends/error.test.ts +++ b/test/extends/error.test.ts @@ -88,7 +88,8 @@ describe('Error', () => { const response = await app.handle(req('/')) - expect(response.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response.status).toBe(500) expect(response.headers.get('content-type')).toBe('application/json') }) diff --git a/test/extends/models.test.ts b/test/extends/models.test.ts index f4fd880d..d9141131 100644 --- a/test/extends/models.test.ts +++ b/test/extends/models.test.ts @@ -315,7 +315,8 @@ describe('Model', () => { .get('/error', () => 1, { response: 'res' }) const error = await app.handle(req('/error')) - expect(error.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(error.status).toBe(500) const correct = await app.handle(req('/correct')) expect(correct.status).toBe(200) @@ -347,7 +348,8 @@ describe('Model', () => { }) const error = await app.handle(req('/error')) - expect(error.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(error.status).toBe(500) const correct = await app.handle(req('/correct')) expect(correct.status).toBe(200) diff --git a/test/path/group.test.ts b/test/path/group.test.ts index 0fb48478..03e8b51e 100644 --- a/test/path/group.test.ts +++ b/test/path/group.test.ts @@ -138,7 +138,8 @@ describe('group', () => { const correct = await app.handle(req('/v1/correct')) expect(correct.status).toBe(200) - expect(error.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(error.status).toBe(500) }) it('validate request with prefix', async () => { diff --git a/test/path/guard.test.ts b/test/path/guard.test.ts index eeb6a631..4c4805de 100644 --- a/test/path/guard.test.ts +++ b/test/path/guard.test.ts @@ -151,7 +151,8 @@ describe('guard', () => { const correct = await app.handle(req('/correct')) expect(correct.status).toBe(200) - expect(error.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(error.status).toBe(500) }) it('apply guard globally', async () => { @@ -168,7 +169,8 @@ describe('guard', () => { const correct = await app.handle(req('/correct')) expect(correct.status).toBe(200) - expect(error.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(error.status).toBe(500) }) it('inherits singleton / definitions and re-meregd on main', async () => { @@ -238,7 +240,8 @@ describe('guard', () => { ]) expect(called).toBe(3) - expect(response).toEqual([422, 422, 422]) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response).toEqual([500, 500, 500]) }) it('handle as global with local override', async () => { @@ -275,7 +278,8 @@ describe('guard', () => { ]) expect(called).toBe(4) - expect(response).toEqual([422, 200, 422]) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response).toEqual([500, 200, 500]) }) it('handle as global with scoped override', async () => { @@ -312,7 +316,8 @@ describe('guard', () => { ]) expect(called).toBe(5) - expect(response).toEqual([422, 200, 200]) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response).toEqual([500, 200, 200]) }) it('handle as scoped', async () => { @@ -343,7 +348,8 @@ describe('guard', () => { ]) expect(called).toBe(2) - expect(response).toEqual([422, 422, 200]) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response).toEqual([500, 500, 200]) }) it('handle as local', async () => { @@ -371,7 +377,8 @@ describe('guard', () => { ]) expect(called).toBe(1) - expect(response).toEqual([422, 200, 200]) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response).toEqual([500, 200, 200]) }) it('only cast guard', async () => { @@ -399,7 +406,8 @@ describe('guard', () => { ]) expect(called).toBe(3) - expect(response).toEqual([422, 200]) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response).toEqual([500, 200]) }) it('handle merge guard and hook on non-specified responses status', () => { diff --git a/test/standard-schema/reference.test.ts b/test/standard-schema/reference.test.ts index 8ccaaca5..f3b24f98 100644 --- a/test/standard-schema/reference.test.ts +++ b/test/standard-schema/reference.test.ts @@ -121,7 +121,8 @@ describe('Standard Schema Validate', () => { const nonExists = await app.handle(req('/lilith')) expect(exists.status).toBe(200) - expect(nonExists.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(nonExists.status).toBe(500) }) it('validate multiple response', async () => { @@ -151,7 +152,8 @@ describe('Standard Schema Validate', () => { expect(nonExists.status).toBe(404) const invalid = await app.handle(req('/unknown')) - expect(invalid.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(invalid.status).toBe(500) }) it('validate multiple schema together', async () => { diff --git a/test/standard-schema/standalone.test.ts b/test/standard-schema/standalone.test.ts index 68820e86..ca8b3ad1 100644 --- a/test/standard-schema/standalone.test.ts +++ b/test/standard-schema/standalone.test.ts @@ -158,7 +158,8 @@ describe('Standard Schema Standalone', () => { expect(valid).toEqual({ id: 1, name: 'lilith' }) const invalid = await app.handle(req('/focou')) - expect(invalid.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(invalid.status).toBe(500) }) it('validate and normalize multiple response', async () => { @@ -208,7 +209,8 @@ describe('Standard Schema Standalone', () => { expect(fouco).toEqual({ id: 2, name: 'fouco' }) const invalid = await app.handle(req('/unknown')) - expect(invalid.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(invalid.status).toBe(500) }) it('validate multiple schema together', async () => { @@ -354,7 +356,8 @@ describe('Standard Schema Standalone', () => { expect(fouco).toEqual({ id: 2, name: 'fouco' }) const invalid = await app.handle(req('/unknown')) - expect(invalid.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(invalid.status).toBe(500) }) it('validate non-typebox schema', async () => { diff --git a/test/standard-schema/validate.test.ts b/test/standard-schema/validate.test.ts index b602baa5..5bec09d1 100644 --- a/test/standard-schema/validate.test.ts +++ b/test/standard-schema/validate.test.ts @@ -100,7 +100,8 @@ describe('Standard Schema Validate', () => { const nonExists = await app.handle(req('/lilith')) expect(exists.status).toBe(200) - expect(nonExists.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(nonExists.status).toBe(500) }) it('validate multiple response', async () => { @@ -125,7 +126,8 @@ describe('Standard Schema Validate', () => { expect(nonExists.status).toBe(404) const invalid = await app.handle(req('/unknown')) - expect(invalid.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(invalid.status).toBe(500) }) it('validate multiple schema together', async () => { diff --git a/test/validator/novalidate.test.ts b/test/validator/novalidate.test.ts index 4bfa0669..d5f22f67 100644 --- a/test/validator/novalidate.test.ts +++ b/test/validator/novalidate.test.ts @@ -204,7 +204,8 @@ describe('ElysiaType.NoValidate', () => { const res = await app.handle(req('/')) - expect(res.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(res.status).toBe(500) }) it('should work with NoValidate on nested object properties', async () => { @@ -248,7 +249,8 @@ describe('ElysiaType.NoValidate', () => { const res = await app.handle(req('/')) - expect(res.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(res.status).toBe(500) }) it('should validate normally with strict object schemas', async () => { @@ -263,7 +265,8 @@ describe('ElysiaType.NoValidate', () => { const res = await app.handle(req('/')) - expect(res.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(res.status).toBe(500) }) it('should handle null values with NoValidate', async () => { diff --git a/test/validator/response.test.ts b/test/validator/response.test.ts index e1bb36b3..1d0baa4b 100644 --- a/test/validator/response.test.ts +++ b/test/validator/response.test.ts @@ -191,7 +191,8 @@ describe('Response Validator', () => { const res = await app.handle(req('/')) - expect(res.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(res.status).toBe(500) }) it('handle File', async () => { @@ -291,9 +292,10 @@ describe('Response Validator', () => { ) expect(r200valid.status).toBe(200) - expect(r200invalid.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(r200invalid.status).toBe(500) expect(r201valid.status).toBe(201) - expect(r201invalid.status).toBe(422) + expect(r201invalid.status).toBe(500) }) it('validate response per status with error()', async () => { @@ -422,7 +424,8 @@ describe('Response Validator', () => { app.handle(req('/validate-error')).then((x) => x.status) ]) - expect(response).toEqual([200, 418, 422]) + // Response validation errors return 500 (server error) - see issue #1480 + expect(response).toEqual([200, 418, 500]) }) it('validate nested references', async () => { @@ -563,3 +566,194 @@ describe('Response Validator', () => { expect(result.join('')).toContain('data: {"name":"Name"}') }) }) + +// https://github.com/elysiajs/elysia/issues/1480 +describe('Response Validation Error Status Code', () => { + it('should return 500 for response validation errors', async () => { + // Response validation errors are server bugs - the server is returning + // data that doesn't match its own declared schema + const app = new Elysia().get( + '/', + () => ({ wrong: 'field' }), + { + response: t.Object({ name: t.String() }) + } + ) + + const res = await app.handle(req('/')) + expect(res.status).toBe(500) + }) + + it('should return 500 with correct error structure for response validation', async () => { + const app = new Elysia().get( + '/', + () => ({ count: 'not a number' }), + { + response: t.Object({ count: t.Number() }) + } + ) + + const res = await app.handle(req('/')) + expect(res.status).toBe(500) + + const body = await res.json() + expect(body.type).toBe('validation') + expect(body.on).toBe('response') + }) + + it('should return 500 for response validation with status-specific schema', async () => { + const app = new Elysia().get( + '/', + () => ({ invalid: 'data' }), + { + response: { + 200: t.Object({ success: t.Boolean() }) + } + } + ) + + const res = await app.handle(req('/')) + expect(res.status).toBe(500) + }) + + it('should return 500 when response has missing required fields', async () => { + const app = new Elysia().get( + '/', + // @ts-ignore - intentionally returning incomplete object + () => ({ name: 'test' }), + { + response: t.Object({ + name: t.String(), + age: t.Number(), + email: t.String() + }) + } + ) + + const res = await app.handle(req('/')) + expect(res.status).toBe(500) + }) + + it('should return 500 when response has wrong type', async () => { + const app = new Elysia().get( + '/', + () => 'string instead of object', + { + response: t.Object({ name: t.String() }) + } + ) + + const res = await app.handle(req('/')) + expect(res.status).toBe(500) + }) + + it('should return 200 when response passes validation', async () => { + const app = new Elysia().get( + '/', + () => ({ name: 'valid', count: 42 }), + { + response: t.Object({ + name: t.String(), + count: t.Number() + }) + } + ) + + const res = await app.handle(req('/')) + expect(res.status).toBe(200) + }) + + it('should return 422 for request body validation errors (not 500)', async () => { + // Request validation errors are client errors - the client sent invalid data + const app = new Elysia().post( + '/', + ({ body }) => body, + { + body: t.Object({ name: t.String() }) + } + ) + + const res = await app.handle( + new Request('http://localhost/', { + method: 'POST', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ wrong: 'field' }) + }) + ) + expect(res.status).toBe(422) + }) + + it('should return 422 for query validation errors (not 500)', async () => { + const app = new Elysia().get( + '/', + ({ query }) => query, + { + query: t.Object({ required: t.String() }) + } + ) + + // Missing required query parameter + const res = await app.handle(req('/')) + expect(res.status).toBe(422) + }) + + it('should return 422 for params validation errors (not 500)', async () => { + const app = new Elysia().get( + '/user/:id', + ({ params }) => params, + { + params: t.Object({ id: t.Numeric() }) + } + ) + + // Invalid param (not numeric) + const res = await app.handle(req('/user/not-a-number')) + expect(res.status).toBe(422) + }) + + it('should return 422 for headers validation errors (not 500)', async () => { + const app = new Elysia().get( + '/', + ({ headers }) => headers, + { + headers: t.Object({ 'x-required-header': t.String() }) + } + ) + + // Missing required header + const res = await app.handle(req('/')) + expect(res.status).toBe(422) + }) + + it('should distinguish between response (500) and request (422) errors in same route', async () => { + const app = new Elysia().post( + '/', + // @ts-ignore - intentionally returning wrong type + ({ body }) => ({ wrong: body.name }), + { + body: t.Object({ name: t.String() }), + response: t.Object({ greeting: t.String() }) + } + ) + + // Valid request but invalid response - should be 500 + const validRequest = await app.handle( + new Request('http://localhost/', { + method: 'POST', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ name: 'test' }) + }) + ) + expect(validRequest.status).toBe(500) + + // Invalid request - should be 422 + const invalidRequest = await app.handle( + new Request('http://localhost/', { + method: 'POST', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ wrong: 'field' }) + }) + ) + expect(invalidRequest.status).toBe(422) + }) +}) diff --git a/test/validator/standalone.test.ts b/test/validator/standalone.test.ts index 1ec7144a..85737e52 100644 --- a/test/validator/standalone.test.ts +++ b/test/validator/standalone.test.ts @@ -29,7 +29,8 @@ describe('standalone validator', () => { }) ) - expect(incorrect.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(incorrect.status).toBe(500) }) it('merge guard with local schema', async () => { @@ -65,7 +66,8 @@ describe('standalone validator', () => { }) ) - expect(incorrect.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(incorrect.status).toBe(500) }) it('merge multiple guard without local schema', async () => { @@ -94,7 +96,8 @@ describe('standalone validator', () => { }) ) - expect(incorrect.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(incorrect.status).toBe(500) }) it('merge multiple guard with local schema', async () => { @@ -133,7 +136,8 @@ describe('standalone validator', () => { }) ) - expect(incorrect.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(incorrect.status).toBe(500) }) it('use override guard when local is not provided', async () => { @@ -169,7 +173,8 @@ describe('standalone validator', () => { }) ) - expect(incorrect.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(incorrect.status).toBe(500) }) it('override guard when local is provided', async () => { @@ -202,6 +207,7 @@ describe('standalone validator', () => { }) ) + // Body validation error - client sent wrong data (422) expect(incorrect.status).toBe(422) }) @@ -256,7 +262,8 @@ describe('standalone validator', () => { }) ) - expect(incorrect.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(incorrect.status).toBe(500) }) it('override additionalProperties while merging guards', async () => { @@ -305,6 +312,7 @@ describe('standalone validator', () => { }) ) + // Body validation error - client sent wrong data (422) expect(incorrect.status).toBe(422) }) diff --git a/test/validator/validator.test.ts b/test/validator/validator.test.ts index 1da9cf18..fdab08ee 100644 --- a/test/validator/validator.test.ts +++ b/test/validator/validator.test.ts @@ -23,7 +23,8 @@ describe('Validator Additional Case', () => { expect(await res.text()).toBe('Mutsuki need correction 💢💢💢') expect(res.status).toBe(200) - expect(invalid.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(invalid.status).toBe(500) }) it('validate afterHandle', async () => { @@ -43,7 +44,8 @@ describe('Validator Additional Case', () => { expect(await res.text()).toBe('Mutsuki need correction 💢💢💢') expect(res.status).toBe(200) - expect(invalid.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(invalid.status).toBe(500) }) it('validate beforeHandle with afterHandle', async () => { @@ -67,7 +69,8 @@ describe('Validator Additional Case', () => { expect(await res.text()).toBe('Mutsuki need correction 💢💢💢') expect(res.status).toBe(200) - expect(invalid.status).toBe(422) + // Response validation errors return 500 (server error) - see issue #1480 + expect(invalid.status).toBe(500) }) it('handle guard hook', async () => { From 96459908fe2d508cc869327e4360a147bb530d25 Mon Sep 17 00:00:00 2001 From: RAUNAK <122172696+aunak@users.noreply.github.com> Date: Thu, 15 Jan 2026 02:32:48 +0530 Subject: [PATCH 2/2] fix: correct issue reference in test comment (#1480) --- test/core/as.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/as.test.ts b/test/core/as.test.ts index 44000e7c..05a6084f 100644 --- a/test/core/as.test.ts +++ b/test/core/as.test.ts @@ -104,7 +104,7 @@ describe('as', () => { ]) expect(called).toBe(3) - // Response validation errors return 500 (server error) - see issue rgba(23, 73, 137, 0) + // Response validation errors return 500 (server error) - see issue #1480 expect(response).toEqual([500, 500, 500]) })