web/elements: throw error in form

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-03-25 22:07:54 +01:00
parent 02212406c4
commit 72cca0473a

View file

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