web/elements: throw error in form
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
02212406c4
commit
72cca0473a
|
@ -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<T> extends LitElement {
|
||||
|
||||
|
@ -27,7 +35,7 @@ export class Form<T> extends LitElement {
|
|||
return [PFBase, PFCard, PFButton, PFForm, PFFormControl, AKGlobal];
|
||||
}
|
||||
|
||||
submit(ev: Event): Promise<T | ErrorResponse> | undefined {
|
||||
submit(ev: Event): Promise<T> | undefined {
|
||||
ev.preventDefault();
|
||||
const ironForm = this.shadowRoot?.querySelector("iron-form");
|
||||
if (!ironForm) {
|
||||
|
@ -57,7 +65,7 @@ export class Form<T> extends LitElement {
|
|||
element.invalid = true;
|
||||
}
|
||||
});
|
||||
return errorMessage;
|
||||
throw new APIError(errorMessage);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue