From a0ff397bf003d26b517d3e6cb304ed6d896630e2 Mon Sep 17 00:00:00 2001 From: Daniel LaCosse <3759828+daniellacosse@users.noreply.github.com> Date: Wed, 17 Apr 2024 14:59:42 -0400 Subject: [PATCH] feat(client): add cause to custom error --- client/src/www/app/app.ts | 7 +++++++ .../outline_server_repository/access_key_serialization.ts | 2 +- client/src/www/model/errors.ts | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/client/src/www/app/app.ts b/client/src/www/app/app.ts index 341d9f3eb3..eb2df4ca58 100644 --- a/client/src/www/app/app.ts +++ b/client/src/www/app/app.ts @@ -220,6 +220,13 @@ export class App { }; } else if (error instanceof errors.SessionConfigError) { toastMessage = error.message; + + if (error.cause) { + buttonMessage = this.localize('error-details'); + buttonHandler = () => { + this.showErrorDetailDialog(error); + }; + } } else { const hasErrorDetails = Boolean(error.message || error.cause); toastMessage = this.localize('error-unexpected'); diff --git a/client/src/www/app/outline_server_repository/access_key_serialization.ts b/client/src/www/app/outline_server_repository/access_key_serialization.ts index a3c57f7b97..b0cd611a1e 100644 --- a/client/src/www/app/outline_server_repository/access_key_serialization.ts +++ b/client/src/www/app/outline_server_repository/access_key_serialization.ts @@ -40,7 +40,7 @@ function parseShadowsocksSessionConfigJson(responseBody: string): ShadowsocksSes const responseJson = JSON.parse(responseBody); if ('error' in responseJson) { - throw new errors.SessionConfigError(responseJson.error.message); + throw new errors.SessionConfigError(responseJson.error.message, { cause: responseJson.error.cause }); } const {method, password, server, server_port, prefix} = responseJson; diff --git a/client/src/www/model/errors.ts b/client/src/www/model/errors.ts index 09fef3ab9b..5d29fa3c54 100644 --- a/client/src/www/model/errors.ts +++ b/client/src/www/model/errors.ts @@ -46,8 +46,8 @@ export class SessionConfigFetchFailed extends CustomError { } export class SessionConfigError extends CustomError { - constructor(message: string) { - super(message); + constructor(message: string, options?: {cause?: Error}) { + super(message, options); } }