diff --git a/CHANGELOG.md b/CHANGELOG.md index 5927ccba..f12c5604 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.2.8 - 27 Dec 2024 +Bug fix: +- [#966](https://github.com/elysiajs/elysia/issues/966) generic error somehow return 200 + # 1.2.7 - 27 Dec 2024 Bug fix: - macro doesn't work with guard @@ -7,7 +11,7 @@ Bug fix: - [#952](https://github.com/elysiajs/elysia/issues/952) onAfterResponse does not provide mapped response value unless aot is disabled - `mapResponse.response` is `{}` if no response schema is provided - Response doesn't reconcile when handler return `Response` is used with `mapResponse` -- `onError` now accept `error` as `number` when `Elysia.error` is thrown (but not return) +- `onError` now accepts `error` as `number` when `Elysia.error` is thrown (but not returned) # 1.2.6 - 25 Dec 2024 Bug fix: diff --git a/example/a.ts b/example/a.ts index 048dc5e1..20b279a8 100644 --- a/example/a.ts +++ b/example/a.ts @@ -1,9 +1,9 @@ -import { Elysia, t, error } from '../src' +import { Elysia, t, error, StatusMap } from '../src' import { req } from '../test/utils' const app = new Elysia() .get('/', () => { - throw error("I'm a teapot") + throw new Error("A") }) .listen(3000) diff --git a/package.json b/package.json index b33a2624..9fa0adbb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "elysia", "description": "Ergonomic Framework for Human", - "version": "1.2.7", + "version": "1.2.8", "author": { "name": "saltyAom", "url": "https://github.com/SaltyAom", diff --git a/src/adapter/web-standard/index.ts b/src/adapter/web-standard/index.ts index 3052f53c..8d427894 100644 --- a/src/adapter/web-standard/index.ts +++ b/src/adapter/web-standard/index.ts @@ -187,7 +187,7 @@ export const WebStandardAdapter: ElysiaAdapter = { unknownError: `return new Response(` + `error.message,` + - `{headers:set.headers,status:error.status}` + + `{headers:set.headers,status:error.status??set.status??500}` + `)` }, listen() { diff --git a/test/core/handle-error.test.ts b/test/core/handle-error.test.ts index 6fee2d4a..6b1cbf2b 100644 --- a/test/core/handle-error.test.ts +++ b/test/core/handle-error.test.ts @@ -306,4 +306,34 @@ describe('Handle Error', () => { expect(response.headers.get('content-type')).toStartWith('text/plain') expect(response.status).toEqual(422) }) + + it('handle generic error', async () => { + const res = await new Elysia() + .get('/', () => 'Hi') + // @ts-expect-error private + .handleError( + { + request, + set: { + headers: {} + } + }, + // https://youtube.com/shorts/PbIWVPKHfrQ + new Error('a') + ) + + expect(await res.text()).toBe('a') + expect(res.status).toBe(500) + }) + + it('handle generic error when thrown in handler', async () => { + const app = new Elysia().get('/', () => { + throw new Error('a') + }) + + const res = await app.handle(req('/')) + + expect(await res.text()).toBe('a') + expect(res.status).toBe(500) + }) })