web/admin: fix error when prompt previewing fails when loading the page (#5290)

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2023-04-18 14:53:13 +02:00 committed by GitHub
parent f44175303b
commit 6a554ef45a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -65,20 +65,20 @@ export class PromptForm extends ModelForm<Prompt, string> {
const prompt = await new StagesApi(DEFAULT_CONFIG).stagesPromptPromptsRetrieve({ const prompt = await new StagesApi(DEFAULT_CONFIG).stagesPromptPromptsRetrieve({
promptUuid: pk, promptUuid: pk,
}); });
this.preview = await new StagesApi(DEFAULT_CONFIG).stagesPromptPromptsPreviewCreate({ await this.refreshPreview(prompt);
promptRequest: prompt,
});
return prompt; return prompt;
} }
async refreshPreview(): Promise<void> { async refreshPreview(prompt?: Prompt): Promise<void> {
const data = this.serializeForm(); if (!prompt) {
if (!data) { prompt = this.serializeForm();
return; if (!prompt) {
return;
}
} }
try { try {
this.preview = await new StagesApi(DEFAULT_CONFIG).stagesPromptPromptsPreviewCreate({ this.preview = await new StagesApi(DEFAULT_CONFIG).stagesPromptPromptsPreviewCreate({
promptRequest: data, promptRequest: prompt,
}); });
this.previewError = undefined; this.previewError = undefined;
} catch (exc) { } catch (exc) {