Interface FetcherResponseInfo

Overview

Represents the response information returned from a request made by a Fetcher.

Key points of note
  • The request should NOT throw an error on non-2xx status codes.
  • The body is returned as a string.
  • The headers are normalized into a plain JavaScript object.
  • Includes metadata such as HTTP status code, status text, and URL.
  • The HTTP version used is explicitly specified.
  • Additional debugging information may be included via extraLogInfo.

See

  • Fetcher
  • FetcherRequestInfo
interface FetcherResponseInfo {
    body?: string;
    extraLogInfo?: Record<string, unknown>;
    headers: Record<string, string>;
    httpVersion: 1 | 2;
    status: number;
    statusText: string;
    url: string;
}

Properties

body?: string
Overview

The body of the request, as a string, if present.

May be left as any falsy value if no body was present (e.g. null, undefined, '', etc.).

Important

Do not attempt to parse the body or convert it to a different format. Simply return it as a string.

For example, use await resp.text(), not await resp.json().

  • resp.text() generally returns an empty string if the body is empty, so it's perfectly safe to use.
  • However, double check that this is true of your fetch implementation before using it.
extraLogInfo?: Record<string, unknown>
Overview

An optional object that may contain any extra debugging information you want to include.

Note that the final extraLogInfo object may contain other fields as well, depending on what method was used.

  • For example, collection.insertMany may set a records and ordered field in extraLogInfo.
headers: Record<string, string>
Overview

The response headers, formatted as a plain old JavaScript object.

Important

Ensure that the headers are correctly normalized into a plain object. They should not be returned as a Headers object or similar.

You may need to do something like the following:

Example

const headers = Object.fromEntries(resp.headers.entries());

// or

const headers = {} as Record<string, string>;

resp.headers.forEach((value, key) => {
headers[key] = value;
});
httpVersion: 1 | 2
Overview

The HTTP version used for the request.

Possible values:

  • 1 → HTTP/1.1
  • 2 → HTTP/2

Ensure that this matches the forceHttp1 flag in FetcherRequestInfo if applicable.

This is just used for debugging purposes.

status: number
Overview

The exact HTTP status code of the response.

  • e.g. 200, 404, 500
Important

Do not throw an error on non-2xx status codes. The response should be returned as-is.

Catch any HTTP error thrown if necessary, and return it as a response.

Otherwise, see if your fetch implementation has a way to disable error-ing on non-2xx status codes.

For example, with axios, you can set validateStatus: () => true to disable this behavior.

statusText: string
Overview

The status text of the response.

  • Example values: "OK", "Not Found", "Internal Server Error"
  • Typically corresponds to the status code.

This is just used for debugging purposes.

url: string
Overview

The URL to which the request was made.

This may be different from the original URL if the request was redirected.

This is just used for debugging purposes.