web/admin: improve error handling in TokenCopyButton

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-05-21 15:56:06 +02:00
parent 75d6cd1674
commit b8fdb82adc
2 changed files with 650 additions and 797 deletions

View file

@ -6,6 +6,8 @@ import { CoreApi } from "@goauthentik/api";
import { DEFAULT_CONFIG } from "../../api/Config";
import { ERROR_CLASS, SECONDARY_CLASS, SUCCESS_CLASS } from "../../constants";
import { PFSize } from "../Spinner";
import { MessageLevel } from "../messages/Message";
import { showMessage } from "../messages/MessageContainer";
import { ActionButton } from "./ActionButton";
@customElement("ak-token-copy-button")
@ -90,7 +92,14 @@ export class TokenCopyButton extends ActionButton {
this.setDone(SUCCESS_CLASS);
});
})
.catch((err: Response | undefined) => {
.catch((err: Response | Error) => {
if (err instanceof Error) {
showMessage({
level: MessageLevel.error,
message: err.message,
});
return;
}
return err?.json().then((errResp) => {
this.setDone(ERROR_CLASS);
throw new Error(errResp["detail"]);

File diff suppressed because it is too large Load diff