fail (@shadow-js/dusk/client)
Makes a failure result. (fail of @shadow-js/dusk/client)
Makes a failure result. Return it from a server function, or from a form function, instead of
throwing: the call still succeeds on the wire, the browser sees failed and the page keeps its
input. A thrown HttpError is the other way to answer with an error; it is shown as an error result.
Import#
ts
import { fail } from "@shadow-js/dusk/client";
Signature#
ts
function fail<Data = undefined>(status: number, data?: Data): ActionFailure<Data>
Parameters#
| Name | Description |
|---|---|
status |
An HTTP status from 400 to 599. |
data |
What to show: { issues: [{ message, path }] } puts problems on fields. |
Returns#
The failure value.
Throws#
- RangeError when
statusis not an integer from 400 to 599.
Examples#
ts
export const signUp = serverFn({ form: true }, (input) =>
taken(input.email) ? fail(409, { issues: [{ message: "Taken", path: ["email"] }] }) : { ok: true },
);