ui/ui_fetch.ts

Authenticated fetch helper for cookie-based session auth.

Wraps the standard fetch with credentials: 'include' so cookies are sent with every request. Use for all API calls in apps that rely on @fuzdev/fuz_app session middleware.

view source

Declarations
#

3 declarations

format_error_body
#

ui/ui_fetch.ts view source

(body: unknown, fallback: string): string import {format_error_body} from '@fuzdev/fuz_app/ui/ui_fetch.js';

The text to show for an error body: its message when it carries one, else its error code — a body's error is a machine-readable code, and prose, when the server sends any, is in message.

body

the parsed error body, of any shape

type unknown

fallback

the text when the body has neither

type string

returns

string

parse_response_error
#

ui/ui_fetch.ts view source

(response: Response, fallback?: string | undefined): Promise<string> import {parse_response_error} from '@fuzdev/fuz_app/ui/ui_fetch.js';

Safely extract an error message from a non-ok response: its message, else its error code (format_error_body).

Handles responses with non-JSON bodies (e.g. HTML 404 pages) that would throw on response.json().

response

type Response

fallback?

message when the body has no message or error

type string
optional

returns

Promise<string>

ui_fetch
#

ui/ui_fetch.ts view source

(input: URL | RequestInfo, init?: RequestInit | undefined): Promise<Response> import {ui_fetch} from '@fuzdev/fuz_app/ui/ui_fetch.js';

Fetch with credentials included (sends cookies).

input

type RequestInfo | URL

init?

type RequestInit
optional

returns

Promise<Response>

Imported by
#