Skip to content

docs: Add docs of RobustFetch #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions rest/robustFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ export interface AbortError {

export type FetchError = NetworkError | AbortError;

/**
* Represents a function that performs a network request using the Fetch API.
*
* @param input - The resource URL or a {@linkcode Request} object.
* @param init - An optional object containing request options.
* @returns A promise that resolves to a {@linkcode Result} object containing either a {@linkcode Request} or an error.
*/
export type RobustFetch = (
input: RequestInfo | URL,
init?: RequestInit,
) => Promise<Result<Response, FetchError>>;

/**
* Performs a network request using the Fetch API.
* A simple implementation of {@linkcode RobustFetch} that uses {@linkcode fetch}.
*
* @param input - The resource URL or a `Request` object.
* @param input - The resource URL or a {@linkcode Request} object.
* @param init - An optional object containing request options.
* @returns A promise that resolves to a `Result` object containing either a `Response` or an error.
* @returns A promise that resolves to a {@linkcode Result} object containing either a {@linkcode Request} or an error.
*/
export const robustFetch: RobustFetch = async (input, init) => {
const request = new Request(input, init);
Expand Down