From 00cbaaf672544eb95c0a5f7fa825906581fda98c Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 12 Jun 2021 18:18:36 +0200 Subject: [PATCH] web/flows: improve display of errors Signed-off-by: Jens Langhammer --- web/src/flows/FlowExecutor.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/web/src/flows/FlowExecutor.ts b/web/src/flows/FlowExecutor.ts index 5f87ac2a2..3292b8838 100644 --- a/web/src/flows/FlowExecutor.ts +++ b/web/src/flows/FlowExecutor.ts @@ -107,8 +107,8 @@ export class FlowExecutor extends LitElement implements StageHost { }).then((data) => { this.challenge = data; this.postUpdate(); - }).catch((e: Error) => { - this.errorMessage(e.toString()); + }).catch((e: Error | Response) => { + this.errorMessage(e); }).finally(() => { this.loading = false; }); @@ -128,15 +128,21 @@ export class FlowExecutor extends LitElement implements StageHost { this.setBackground(this.challenge.flowInfo.background); } this.postUpdate(); - }).catch((e: Error) => { + }).catch((e: Error | Response) => { // Catch JSON or Update errors - this.errorMessage(e.toString()); + this.errorMessage(e); }).finally(() => { this.loading = false; }); } - errorMessage(error: string): void { + async errorMessage(error: Error | Response): Promise { + let body = ""; + if (error instanceof Error) { + body = error.message; + } else if (error instanceof Response) { + body = await error.text(); + } this.challenge = { type: ChallengeChoices.Shell, body: `