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.

Declarations
#

2 declarations

view source

parse_response_error
#

ui/ui_fetch.ts view source

(response: Response, fallback?: string | undefined): Promise<string>

Safely extract an error message from a non-ok response.

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

response

the non-ok response

type Response

fallback?

fallback message when no .error field is found

type string | undefined
optional

returns

Promise<string>

error message string

ui_fetch
#

ui/ui_fetch.ts view source

(input: RequestInfo | URL, init?: RequestInit | undefined): Promise<Response>

Fetch with credentials included (sends cookies).

input

the request URL or Request object

type RequestInfo | URL

init?

optional fetch init options

type RequestInit | undefined
optional

returns

Promise<Response>

fetch response promise

Imported by
#