|
1 | 1 | <script lang="ts"> |
2 | | - import { defaults, superForm } from '$lib/index.js'; |
3 | | - import { userSchema } from './schema.js'; |
4 | | - import { zod } from '$lib/adapters/zod.js'; |
| 2 | + import { page } from '$app/stores'; |
| 3 | + import SuperDebug from '$lib/client/SuperDebug.svelte'; |
| 4 | + import { superForm } from '$lib/index.js'; |
5 | 5 |
|
6 | | - const formData = defaults({ name: 'First name' }, zod(userSchema)); |
| 6 | + export let data; |
7 | 7 |
|
8 | 8 | let error: string; |
9 | 9 |
|
10 | | - export const spForm = superForm(formData, { |
| 10 | + export const spForm = superForm(data.form, { |
11 | 11 | onError: (e) => { |
12 | | - console.log(e.result.error); |
| 12 | + console.log(e.result); |
13 | 13 | // @ts-expect-error Does not follow the App.Error shape |
14 | 14 | error = 'code' in e.result.error ? e.result.error.code : e.result.error.message; |
15 | 15 | } |
16 | 16 | }); |
17 | 17 |
|
18 | 18 | const { enhance, form } = spForm; |
| 19 | +
|
| 20 | + $: action = |
| 21 | + $form.exception == 'json' |
| 22 | + ? '/v2/app-error/json' |
| 23 | + : $form.exception == 'plain' |
| 24 | + ? '/v2/app-error/plain' |
| 25 | + : undefined; |
| 26 | +
|
| 27 | + // eslint-disable-next-line svelte/valid-compile |
| 28 | + $page; |
19 | 29 | </script> |
20 | 30 |
|
21 | | -<p id="error">ERROR:{error}</p> |
| 31 | +<SuperDebug data={$form} /> |
| 32 | + |
| 33 | +<p id="error">ERROR:{error}:{$page.status}</p> |
22 | 34 |
|
23 | | -<form use:enhance method="POST"> |
24 | | - <input name="name" bind:value={$form.name} /> |
| 35 | +<form method="POST" use:enhance {action}> |
| 36 | + Name: <input name="name" bind:value={$form.name} /> |
| 37 | + <ul style="list-style-type:none"> |
| 38 | + <li> |
| 39 | + <input type="radio" name="exception" value="error" bind:group={$form.exception} /> SvelteKit error |
| 40 | + (502) |
| 41 | + </li> |
| 42 | + <li> |
| 43 | + <input type="radio" name="exception" value="exception" bind:group={$form.exception} /> Exception |
| 44 | + (500) |
| 45 | + </li> |
| 46 | + <li> |
| 47 | + <input type="radio" name="exception" value="json" bind:group={$form.exception} /> 430 JSON response, |
| 48 | + with 429 status (429) |
| 49 | + </li> |
| 50 | + <li> |
| 51 | + <input type="radio" name="exception" value="plain" bind:group={$form.exception} /> 417 error response |
| 52 | + (500) |
| 53 | + </li> |
| 54 | + </ul> |
25 | 55 | <button type="submit">Save</button> |
26 | | - <br /><input type="checkbox" name="exception" bind:checked={$form.exception} /> Throw exception |
27 | 56 | </form> |
0 commit comments