Skip to content

Commit 29e7561

Browse files
committed
docs(error-handling): split 404 and 405 default responses
- Add 405 Method Not Allowed section with Allow header example - Note HEAD is added automatically when a GET handler exists - Scope 404 to paths matching no route pattern
1 parent 82e1441 commit 29e7561

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

docs/error-handling/default-behavior.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Default error handling covers all error types that can occur during request proc
5252

5353
### 404 - Route Not Found
5454

55-
When a route doesn't exist or no matching route handler is found:
55+
When no route matches the request path at all:
5656

5757
```typescript
5858
// GET /nonexistent
@@ -64,8 +64,20 @@ When a route doesn't exist or no matching route handler is found:
6464
This includes:
6565

6666
- Non-existent routes
67-
- Routes with incorrect HTTP methods
68-
- Routes that fail to match during routing resolution
67+
- Paths that match no pattern during routing resolution
68+
69+
### 405 - Method Not Allowed
70+
71+
When the path matches a route but the method has no handler, the response is `405` with an `Allow` header listing the supported methods:
72+
73+
```typescript
74+
// DELETE /users (only GET and POST defined)
75+
// Status: 405
76+
// Body: JSON or HTML (by Accept header)
77+
// Headers: { Allow: "GET, HEAD, POST" }
78+
```
79+
80+
`HEAD` is added automatically whenever a `GET` handler exists.
6981

7082
### 500 - Server Errors
7183

docs/id/error-handling/default-behavior.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Penanganan error default mencakup semua jenis error yang bisa terjadi selama pem
5252

5353
### 404 - Rute Tidak Ditemukan
5454

55-
Ketika rute tidak ada atau tidak ada route handler yang cocok:
55+
Ketika tidak ada rute yang cocok dengan path request sama sekali:
5656

5757
```typescript
5858
// GET /nonexistent
@@ -64,8 +64,20 @@ Ketika rute tidak ada atau tidak ada route handler yang cocok:
6464
Ini mencakup:
6565

6666
- Rute yang tidak ada
67-
- Rute dengan metode HTTP yang salah
68-
- Rute yang gagal cocok saat resolusi routing
67+
- Path yang tidak cocok dengan pola mana pun saat resolusi routing
68+
69+
### 405 - Metode Tidak Diizinkan
70+
71+
Ketika path cocok dengan sebuah rute tapi metodenya tidak punya handler, response-nya **405** dengan header `Allow` yang mendaftar metode yang didukung:
72+
73+
```typescript
74+
// DELETE /users (hanya GET dan POST terdefinisi)
75+
// Status: 405
76+
// Body: JSON atau HTML (lewat header Accept)
77+
// Headers: { Allow: "GET, HEAD, POST" }
78+
```
79+
80+
`HEAD` ditambahkan otomatis setiap kali handler `GET` ada.
6981

7082
### 500 - Error Server
7183

0 commit comments

Comments
 (0)