Skip to content

Commit 69bab41

Browse files
committed
docs(observability): centralize catch-vs-on guidance
- Add catch-vs-on diagram to defense-in-depth recording section - Replace duplicated errors-page block with a defense-in-depth link
1 parent 29e7561 commit 69bab41

4 files changed

Lines changed: 6 additions & 76 deletions

File tree

docs/error-handling/defense-in-depth.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ This is the safety net behind everything else. See [Process Protection](/getting
118118

119119
Shaping a response and recording a failure are separate jobs. `router.catch()` controls what the client sees, while [`router.on()`](/middleware/observability/overview) records what happened for logs and metrics. Wire both for full coverage:
120120

121+
![One failed request fans out to two independent hooks, where router.catch shapes the Response the client receives with a controlled status and body, and router.on records the same failure into logs and metrics without affecting the reply](/diagrams/obs-catch-vs-on.png)
122+
121123
```typescript twoslash
122124
import { Router } from '@neabyte/deserve'
123125

docs/id/error-handling/defense-in-depth.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ Ini jaring pengaman di balik semua yang lain. Lihat [Proteksi Proses](/id/gettin
118118

119119
Membentuk response dan mencatat kegagalan adalah tugas terpisah. `router.catch()` mengontrol apa yang dilihat klien, sementara [`router.on()`](/id/middleware/observability/overview) mencatat apa yang terjadi untuk log dan metrik. Pasang keduanya untuk cakupan penuh:
120120

121+
![Satu request gagal menyebar ke dua hook independen, di mana router.catch membentuk Response yang diterima klien dengan status dan body terkontrol, dan router.on mencatat kegagalan yang sama ke log dan metrik tanpa memengaruhi balasan](/diagrams/obs-catch-vs-on.png)
122+
121123
```typescript twoslash
122124
import { Router } from '@neabyte/deserve'
123125

docs/id/middleware/observability/errors.md

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -76,41 +76,4 @@ router.on((event) => {
7676

7777
## Memasangkan Dengan Penanganan Error
7878

79-
Dua hook menangani tugas berbeda:
80-
81-
- [`router.catch()`](/id/error-handling/object-details) membentuk response yang diterima klien.
82-
- `router.on()` mencatat apa yang terjadi untuk log dan metrik.
83-
84-
Pakai `catch` untuk mengontrol balasan, dan `on` untuk mengamatinya. Pengaturan umum memasang keduanya:
85-
86-
![Satu request gagal menyebar ke dua hook independen, di mana router.catch membentuk Response yang diterima klien dengan status dan body terkontrol, dan router.on mencatat kegagalan yang sama ke log dan metrik tanpa memengaruhi balasan](/diagrams/obs-catch-vs-on.png)
87-
88-
```typescript twoslash
89-
import { Router } from '@neabyte/deserve'
90-
91-
const router = new Router({
92-
routesDir: './routes'
93-
})
94-
// ---cut---
95-
// Bentuk response klien
96-
router.catch((ctx, info) => {
97-
return ctx.send.json(
98-
{
99-
error: 'Something went wrong'
100-
},
101-
{
102-
status: info.statusCode
103-
}
104-
)
105-
})
106-
107-
// Catat kegagalan untuk nanti
108-
router.on((event) => {
109-
if (event.kind === 'request:error') {
110-
const { url, error } = event.metadata as { url: string; error?: Error }
111-
console.error(url, error?.message)
112-
}
113-
})
114-
```
115-
116-
Untuk response default ketika tidak ada handler diatur, lihat [Perilaku Default](/id/error-handling/default-behavior).
79+
Membentuk response dan mencatat kegagalan adalah dua tugas terpisah. [`router.catch()`](/id/error-handling/object-details) mengontrol apa yang dilihat klien, sementara `router.on()` mencatat apa yang terjadi untuk log dan metrik. Keduanya berjalan independen, dan cara memasang keduanya dibahas di [Pertahanan Berlapis](/id/error-handling/defense-in-depth#mencatat-di-seluruh-lapisan).

docs/middleware/observability/errors.md

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -76,41 +76,4 @@ router.on((event) => {
7676

7777
## Pairing With Error Handling
7878

79-
Two hooks cover different jobs:
80-
81-
- [`router.catch()`](/error-handling/object-details) shapes the response a client receives.
82-
- `router.on()` records what happened for logs and metrics.
83-
84-
Use `catch` to control the reply, and `on` to observe it. A typical setup wires both:
85-
86-
![One failed request fans out to two independent hooks, where router.catch shapes the Response the client receives with a controlled status and body, and router.on records the same failure into logs and metrics without affecting the reply](/diagrams/obs-catch-vs-on.png)
87-
88-
```typescript twoslash
89-
import { Router } from '@neabyte/deserve'
90-
91-
const router = new Router({
92-
routesDir: './routes'
93-
})
94-
// ---cut---
95-
// Shape the client response
96-
router.catch((ctx, info) => {
97-
return ctx.send.json(
98-
{
99-
error: 'Something went wrong'
100-
},
101-
{
102-
status: info.statusCode
103-
}
104-
)
105-
})
106-
107-
// Record the failure for later
108-
router.on((event) => {
109-
if (event.kind === 'request:error') {
110-
const { url, error } = event.metadata as { url: string; error?: Error }
111-
console.error(url, error?.message)
112-
}
113-
})
114-
```
115-
116-
For the default response when no handler is set, see [Default Behavior](/error-handling/default-behavior).
79+
Shaping a response and recording a failure are separate jobs. [`router.catch()`](/error-handling/object-details) controls what the client sees, while `router.on()` records what happened for logs and metrics. The two run independently, and wiring both is covered in [Defense in Depth](/error-handling/defense-in-depth#recording-across-layers).

0 commit comments

Comments
 (0)