Skip to content

Commit 038f1a1

Browse files
author
jarvisjiang
committed
docs(codebuddy): update CODEBUDDY.md
- Add 'bytes' to FetchResponseType union - Update dependency versions to latest - Update test count from 28 to 83 - Add Error Handling Design section explaining sync vs async errors
1 parent 356a3ee commit 038f1a1

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

CODEBUDDY.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,24 @@ src/
183183
- `when?: number[] | ((error: Error, attempt: number) => boolean)` - Retry conditions
184184
- `onRetry?: (error: Error, attempt: number) => void` - Callback before retry
185185
- `FetchProgress` - Progress tracking with `totalByteLength` and `completedByteLength`
186-
- `FetchResponseType` - Union type: `'text' | 'arraybuffer' | 'blob' | 'json' | 'stream'`
186+
- `FetchResponseType` - Union type: `'text' | 'arraybuffer' | 'blob' | 'json' | 'bytes' | 'stream'`
187187
- `FetchResponse<T, E>` - Type alias for `AsyncResult<T, E>` from happy-rusty
188188
- `FetchError` - Custom error class with `status: number` property for HTTP status codes
189189

190190
### Dependencies
191191

192192
**Runtime:**
193-
- `happy-rusty` (^1.8.0) - Provides Result/AsyncResult types for functional error handling
193+
- `happy-rusty` (^1.9.0) - Provides Result/AsyncResult types for functional error handling
194194

195195
**Dev:**
196196
- TypeScript (^5.9.3) - Type checking and compilation
197-
- Vite (^7.3.0) - Build tool and dev server
197+
- Vite (^7.3.1) - Build tool and dev server
198198
- `vite-plugin-dts` (^4.5.4) - Bundles TypeScript definitions
199-
- Vitest (^4.0.16) - Test framework
200-
- `@vitest/coverage-v8` (^4.0.16) - Coverage provider
199+
- Vitest (^4.0.17) - Test framework
200+
- `@vitest/coverage-v8` (^4.0.17) - Coverage provider
201201
- MSW (^2.12.7) - Mock Service Worker for API mocking in tests
202-
- ESLint (^9.39.2) + typescript-eslint (^8.51.0) - Linting
203-
- TypeDoc (^0.28.15) - Documentation generation
202+
- ESLint (^9.39.2) + typescript-eslint (^8.53.0) - Linting
203+
- TypeDoc (^0.28.16) - Documentation generation
204204

205205
**External dependencies are marked as external in vite.config.ts** - they are not bundled.
206206

@@ -252,7 +252,7 @@ src/
252252
- Tests are in `tests/fetch.test.ts`
253253
- Uses Vitest as test framework
254254
- Uses MSW (Mock Service Worker) for HTTP mocking
255-
- 28 test cases with 100% coverage
255+
- 83 test cases with 100% coverage
256256
- Coverage includes:
257257
- All response types (text, arraybuffer, blob, JSON)
258258
- HTTP methods (GET, POST, PUT, PATCH, DELETE)
@@ -346,6 +346,20 @@ The `prepublishOnly` script automatically runs `pnpm run build`, which includes:
346346
- CHANGELOG.md
347347
- dist/
348348

349+
## Error Handling Design
350+
351+
`fetchT` distinguishes between two types of errors:
352+
353+
### Programming Errors (Synchronous)
354+
Invalid parameters throw immediately for fail-fast behavior:
355+
- `TypeError` for type validation (wrong type, not a function, invalid enum value)
356+
- `Error` for value range validation (negative numbers, zero/negative timeout)
357+
358+
This differs from native `fetch`, which returns rejected Promises for parameter errors. Synchronous throws provide clearer stack traces and catch bugs during development.
359+
360+
### Runtime Errors (Result Type)
361+
Network failures and HTTP errors are wrapped in `Result` type via `happy-rusty`. Use `.isOk()`, `.isErr()`, `.unwrap()`, `.unwrapErr()` for conditional handling.
362+
349363
## Known Issues & Gotchas
350364

351365
1. **Progress tracking requires Content-Length header**: If the server doesn't send this header, progress tracking will fail (onProgress receives an Err). The `Headers.get()` method is case-insensitive per the HTTP spec.

0 commit comments

Comments
 (0)