diff --git a/web/src/elements/forms/Form.ts b/web/src/elements/forms/Form.ts index 81907318f..a5cc50006 100644 --- a/web/src/elements/forms/Form.ts +++ b/web/src/elements/forms/Form.ts @@ -10,10 +10,18 @@ import AKGlobal from "../../authentik.css"; import PFForm from "@patternfly/patternfly/components/Form/form.css"; import PFFormControl from "@patternfly/patternfly/components/FormControl/form-control.css"; -export interface ErrorResponse { +interface ErrorResponse { [key: string]: string[]; } +export class APIError extends Error { + + constructor(public response: ErrorResponse) { + super(); + } + +} + @customElement("ak-form") export class Form extends LitElement { @@ -27,7 +35,7 @@ export class Form extends LitElement { return [PFBase, PFCard, PFButton, PFForm, PFFormControl, AKGlobal]; } - submit(ev: Event): Promise | undefined { + submit(ev: Event): Promise | undefined { ev.preventDefault(); const ironForm = this.shadowRoot?.querySelector("iron-form"); if (!ironForm) { @@ -57,7 +65,7 @@ export class Form extends LitElement { element.invalid = true; } }); - return errorMessage; + throw new APIError(errorMessage); }); }