In the browser
serverFnStub(id, { method, form, base }) from @shadow-js/dusk/client is what the build puts in place of each function; you rarely call it yourself.
serverFnStub(id, { method, form, base }) from @shadow-js/dusk/client is what the build puts in place of each
function; you rarely call it yourself. The stub is a function with three extras: .id, .url (the endpoint,
{base}/_dusk/fn/<id>) and .with({ signal, headers, fetch }), which returns a version of the function with
call options. Calls send credentials: "same-origin" and redirect: "manual"; x-dusk-fn and content-type
cannot be replaced through headers. The argument is a single value; extra arguments are dropped. It is optional
when undefined is a valid input and required otherwise, the same rule as for the server-side function.
What a call can do on the client:
| The server | The promise |
|---|---|
| returns | resolves with the decoded value |
throws HttpError or a validation error |
rejects with HttpError (same status, message, data; data.issues for validation) |
throws notFound(), or the id is unknown |
rejects with the router's notFound() signal |
| redirects | rejects with the router's redirect() signal, after the same-origin check |
| fails unexpectedly | rejects with ServerFnError (status, requestId) |
| answers something else | rejects with ServerFnProtocolError |
| the argument cannot be serialized | rejects with TypeError, before any request |