diff --git a/client/src/www/app/app.ts b/client/src/www/app/app.ts index e067987e8a..ae84354d1e 100644 --- a/client/src/www/app/app.ts +++ b/client/src/www/app/app.ts @@ -204,22 +204,30 @@ export class App { toastMessage = this.localize('error-connection-configuration'); buttonMessage = this.localize('error-details'); buttonHandler = () => { - this.showErrorDetailDialog(error); + this.showErrorCauseDialog(error); }; } else if (error instanceof errors.SessionConfigFetchFailed) { toastMessage = this.localize('error-connection-configuration-fetch'); buttonMessage = this.localize('error-details'); buttonHandler = () => { - this.showErrorDetailDialog(error); + this.showErrorCauseDialog(error); }; } else if (error instanceof errors.ProxyConnectionFailure) { toastMessage = this.localize('error-connection-proxy'); buttonMessage = this.localize('error-details'); buttonHandler = () => { - this.showErrorDetailDialog(error); + this.showErrorCauseDialog(error); }; } else if (error instanceof errors.SessionConfigError) { toastMessage = error.message; + } else if (error instanceof errors.SessionProviderError) { + toastMessage = error.message; + buttonMessage = this.localize('error-details'); + + console.log(error, error.message, error.details); + buttonHandler = () => { + this.showErrorDetailsDialog(error.details); + }; } else { const hasErrorDetails = Boolean(error.message || error.cause); toastMessage = this.localize('error-unexpected'); @@ -227,7 +235,7 @@ export class App { if (hasErrorDetails) { buttonMessage = this.localize('error-details'); buttonHandler = () => { - this.showErrorDetailDialog(error); + this.showErrorCauseDialog(error); }; } } @@ -573,7 +581,7 @@ export class App { return new Promise(resolve => resolve(confirm(message))); } - private showErrorDetailDialog(error: Error) { + private showErrorCauseDialog(error: Error) { let message = error.toString(); if (error.cause) { @@ -581,10 +589,15 @@ export class App { message += error.cause.toString(); } - // Temporarily use window.alert here return alert(message); } + private showErrorDetailsDialog(details: string) { + if (!details) return; + + return alert(details); + } + //#endregion UI dialogs // Helpers: 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 12e3d061b7..035ed437b0 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 @@ -39,7 +39,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.SessionProviderError(responseJson.error.message, responseJson.error.details); } const {method, password, server, server_port, prefix} = responseJson; @@ -85,7 +85,7 @@ export async function fetchShadowsocksSessionConfig(configLocation: URL): Promis return parseShadowsocksSessionConfigJson(responseBody); } catch (cause) { - if (cause instanceof errors.SessionConfigError) { + if (cause instanceof errors.SessionProviderError) { throw cause; } diff --git a/client/src/www/model/errors.ts b/client/src/www/model/errors.ts index 8a6a743158..8167bbe29f 100644 --- a/client/src/www/model/errors.ts +++ b/client/src/www/model/errors.ts @@ -47,8 +47,18 @@ export class SessionConfigFetchFailed extends CustomError { } export class SessionConfigError extends CustomError { - constructor(message: string) { + constructor(message: string, options?: {cause?: Error}) { + super(message, options); + } +} + +export class SessionProviderError extends CustomError { + readonly details: string | undefined; + + constructor(message: string, details?: string) { super(message); + + this.details = details; } }