export type WorkerFail = {reason?: (string | null) | undefined}; export type CreateApi0WorkerFailArgs = {body: WorkerFail}; export type CreateApi0WorkerFailOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * POST /0/worker/fail */ export const createApi0WorkerFail = async (args: CreateApi0WorkerFailArgs, options: CreateApi0WorkerFailOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/0/worker/fail${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };