From 00b0902584de31fa9c23ce1c58fd7dfd0cbc40e5 Mon Sep 17 00:00:00 2001 From: Braden Wong <13159333+braden-w@users.noreply.github.com> Date: Fri, 5 Dec 2025 15:45:37 -0800 Subject: [PATCH 1/3] docs(essential): show string status names in lifecycle and error handling Add inline comments showing string alternatives in: - docs/essential/life-cycle.md (script setup demo) - docs/patterns/error-handling.md (script setup and code examples) --- docs/essential/life-cycle.md | 4 ++-- docs/patterns/error-handling.md | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/essential/life-cycle.md b/docs/essential/life-cycle.md index 9d8b49bd..c96bffb9 100644 --- a/docs/essential/life-cycle.md +++ b/docs/essential/life-cycle.md @@ -28,11 +28,11 @@ const demo = new Elysia() }) .get('/throw', ({ status }) => { // This will be caught by onError - throw status(418) + throw status(418) // or status("I'm a teapot") }) .get('/return', ({ status }) => { // This will NOT be caught by onError - return status(418) + return status(418) // or status("I'm a teapot") }) diff --git a/docs/patterns/error-handling.md b/docs/patterns/error-handling.md index 7ad6e6a2..8b3a9436 100644 --- a/docs/patterns/error-handling.md +++ b/docs/patterns/error-handling.md @@ -28,11 +28,11 @@ const demo = new Elysia() }) .get('/throw', ({ error }) => { // This will be caught by onError - throw error(418) + throw error(418) // or error("I'm a teapot") }) .get('/return', ({ status }) => { // This will NOT be caught by onError - return status(418) + return status(418) // or status("I'm a teapot") }) const demo2 = new Elysia() @@ -300,11 +300,11 @@ new Elysia() }) .get('/throw', ({ status }) => { // This will be caught by onError - throw status(418) + throw status(418) // or status("I'm a teapot") }) .get('/return', ({ status }) => { // This will NOT be caught by onError - return status(418) + return status(418) // or status("I'm a teapot") }) ``` From 66260994185650a79bf17eb9458b64d6787b8d48 Mon Sep 17 00:00:00 2001 From: Braden Wong <13159333+braden-w@users.noreply.github.com> Date: Fri, 5 Dec 2025 15:46:15 -0800 Subject: [PATCH 2/3] docs(key-concept): use string status names for auth examples - Change status(401) to status("Unauthorized") for clarity - Remove '// or' comments from auth examples --- docs/essential/life-cycle.md | 4 ++-- docs/key-concept.md | 10 +++++----- docs/patterns/error-handling.md | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/essential/life-cycle.md b/docs/essential/life-cycle.md index c96bffb9..9d8b49bd 100644 --- a/docs/essential/life-cycle.md +++ b/docs/essential/life-cycle.md @@ -28,11 +28,11 @@ const demo = new Elysia() }) .get('/throw', ({ status }) => { // This will be caught by onError - throw status(418) // or status("I'm a teapot") + throw status(418) }) .get('/return', ({ status }) => { // This will NOT be caught by onError - return status(418) // or status("I'm a teapot") + return status(418) }) diff --git a/docs/key-concept.md b/docs/key-concept.md index b831b42d..14111fe8 100644 --- a/docs/key-concept.md +++ b/docs/key-concept.md @@ -19,8 +19,8 @@ import { Elysia } from 'elysia' import Playground from './components/nearl/playground.vue' const profile1 = new Elysia() - .onBeforeHandle(({ status }) => status(401)) - .get('/profile', ({ status }) => status(401)) + .onBeforeHandle(({ status }) => status("Unauthorized")) + .get('/profile', ({ status }) => status("Unauthorized")) const demo1 = new Elysia() .use(profile1) @@ -28,13 +28,13 @@ const demo1 = new Elysia() .patch('/rename', () => 'Updated!') const profile2 = new Elysia() - .onBeforeHandle({ as: 'global' }, ({ status }) => status(401)) - .get('/profile', ({ status }) => status(401)) + .onBeforeHandle({ as: 'global' }, ({ status }) => status("Unauthorized")) + .get('/profile', ({ status }) => status("Unauthorized")) const demo2 = new Elysia() .use(profile2) // This will NOT have sign in check - .patch('/rename', ({ status }) => status(401)) + .patch('/rename', ({ status }) => status("Unauthorized")) # Key Concept diff --git a/docs/patterns/error-handling.md b/docs/patterns/error-handling.md index 8b3a9436..7ad6e6a2 100644 --- a/docs/patterns/error-handling.md +++ b/docs/patterns/error-handling.md @@ -28,11 +28,11 @@ const demo = new Elysia() }) .get('/throw', ({ error }) => { // This will be caught by onError - throw error(418) // or error("I'm a teapot") + throw error(418) }) .get('/return', ({ status }) => { // This will NOT be caught by onError - return status(418) // or status("I'm a teapot") + return status(418) }) const demo2 = new Elysia() @@ -300,11 +300,11 @@ new Elysia() }) .get('/throw', ({ status }) => { // This will be caught by onError - throw status(418) // or status("I'm a teapot") + throw status(418) }) .get('/return', ({ status }) => { // This will NOT be caught by onError - return status(418) // or status("I'm a teapot") + return status(418) }) ``` From b1d0dcfabfc7b7e081ad8b3d6c2c8cf165e96a6f Mon Sep 17 00:00:00 2001 From: Braden Wong Date: Fri, 5 Dec 2025 17:31:13 -0800 Subject: [PATCH 3/3] style: use single quotes for status strings --- docs/key-concept.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/key-concept.md b/docs/key-concept.md index 14111fe8..a5a42f52 100644 --- a/docs/key-concept.md +++ b/docs/key-concept.md @@ -19,8 +19,8 @@ import { Elysia } from 'elysia' import Playground from './components/nearl/playground.vue' const profile1 = new Elysia() - .onBeforeHandle(({ status }) => status("Unauthorized")) - .get('/profile', ({ status }) => status("Unauthorized")) + .onBeforeHandle(({ status }) => status('Unauthorized')) + .get('/profile', ({ status }) => status('Unauthorized')) const demo1 = new Elysia() .use(profile1) @@ -28,13 +28,13 @@ const demo1 = new Elysia() .patch('/rename', () => 'Updated!') const profile2 = new Elysia() - .onBeforeHandle({ as: 'global' }, ({ status }) => status("Unauthorized")) - .get('/profile', ({ status }) => status("Unauthorized")) + .onBeforeHandle({ as: 'global' }, ({ status }) => status('Unauthorized')) + .get('/profile', ({ status }) => status('Unauthorized')) const demo2 = new Elysia() .use(profile2) // This will NOT have sign in check - .patch('/rename', ({ status }) => status("Unauthorized")) + .patch('/rename', ({ status }) => status('Unauthorized')) # Key Concept