mentoss
Version:
A utility to mock fetch requests and responses.
56 lines (55 loc) • 1.98 kB
TypeScript
/**
* Parses a URL and returns a URL object. This is used instead
* of the URL constructor to provide a standard error message,
* because different runtimes use different messages.
* @param {string|URL} url The URL to parse.
* @returns {URL} The parsed URL.
*/
export function parseUrl(url: string | URL): URL;
/**
* Reads the body from a request based on the HTTP headers.
* @param {Request} request The request to read the body from.
* @returns {Promise<string|any|FormData|null>} The body of the request.
*/
export function getBody(request: Request): Promise<string | any | FormData | null>;
/**
* Creates a text representation of a request in the same format as it would
* appear in a network panel.
* @param {Request} request The request to stringify.
* @param {string|any|FormData|null} body The body of the request
* @returns {string} The stringified request.
*/
export function stringifyRequest(request: Request, body: string | any | FormData | null): string;
/**
* Represents an error that occurs when a URL is invalid.
* @extends {Error}
*/
export class URLParseError extends Error {
/**
* Creates a new URLParseError instance.
* @param {string} url The URL that caused the error.
*/
constructor(url: string);
}
/**
* Represents an error that occurs when no route matched a request.
* @extends {Error}
*/
export class NoRouteMatchedError extends Error {
/**
* Creates a new NoRouteMatchedError instance.
* @param {Request} request The request that wasn't matched.
* @param {string|any|FormData|null} body The body of the request.
* @param {Array<{title: string, messages: Array<string>}>} traces The traces from the servers.
*/
constructor(request: Request, body: string | any | FormData | null, traces: Array<{
title: string;
messages: Array<string>;
}>);
request: Request;
body: any;
traces: {
title: string;
messages: Array<string>;
}[];
}