Skip to content

Commit 6b28a23

Browse files
author
jarvisjiang
committed
docs(jsdoc): update fetchT JSDoc with accurate throws documentation
- Add 'bytes' and 'stream' to responseType description - Document sync throws behavior (differs from native fetch) - List all @throws with correct TypeError vs Error distinction - Include retry option validation errors
1 parent 038f1a1 commit 6b28a23

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/fetch/fetch.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,31 @@ export function fetchT(url: string | URL, init?: FetchInit & {
203203
*
204204
* Features:
205205
* - **Abortable requests**: Set `abortable: true` to get a `FetchTask` with `abort()` method.
206-
* - **Type-safe responses**: Use `responseType` to automatically parse responses as text, JSON, ArrayBuffer, or Blob.
206+
* - **Type-safe responses**: Use `responseType` to automatically parse responses as text, JSON, ArrayBuffer, Blob, bytes, or stream.
207207
* - **Timeout support**: Set `timeout` in milliseconds to auto-abort long-running requests.
208208
* - **Progress tracking**: Use `onProgress` callback to track download progress (requires Content-Length header).
209209
* - **Chunk streaming**: Use `onChunk` callback to receive raw data chunks as they arrive.
210210
* - **Retry support**: Use `retry` to automatically retry failed requests with configurable delay and conditions.
211-
* - **Result type error handling**: Returns `Result<T, Error>` instead of throwing exceptions.
211+
* - **Result type error handling**: Returns `Result<T, Error>` instead of throwing exceptions for runtime errors.
212+
*
213+
* **Note**: Invalid parameters throw synchronously (fail-fast) rather than returning rejected Promises.
214+
* This differs from native `fetch` behavior and helps catch programming errors during development.
212215
*
213216
* @typeParam T - The expected type of the response data.
214217
* @param url - The resource to fetch. Can be a URL object or a string representing a URL.
215218
* @param init - Additional options for the fetch operation, extending standard `RequestInit` with custom properties.
216219
* @returns A `FetchTask<T>` if `abortable: true`, otherwise a `FetchResponse<T>` (which is `AsyncResult<T, Error>`).
217-
* @throws {Error} If `url` is not a string or URL object.
218-
* @throws {Error} If `timeout` is specified but is not a positive number.
220+
* @throws {TypeError} If `url` is invalid or a relative URL in non-browser environment.
221+
* @throws {TypeError} If `responseType` is not a valid response type.
222+
* @throws {TypeError} If `timeout` is not a number.
223+
* @throws {Error} If `timeout` is not greater than 0.
224+
* @throws {TypeError} If `onProgress` or `onChunk` is provided but not a function.
225+
* @throws {TypeError} If `retry.retries` is not an integer.
226+
* @throws {Error} If `retry.retries` is negative.
227+
* @throws {TypeError} If `retry.delay` is not a number or function.
228+
* @throws {Error} If `retry.delay` is a negative number.
229+
* @throws {TypeError} If `retry.when` is not an array or function.
230+
* @throws {TypeError} If `retry.onRetry` is provided but not a function.
219231
*
220232
* @example
221233
* // Basic GET request - returns Response object wrapped in Result

0 commit comments

Comments
 (0)