From 2e1db31755f4543ba83f2d9cfd0d7b91d0229933 Mon Sep 17 00:00:00 2001 From: Daniel LaCosse <3759828+daniellacosse@users.noreply.github.com> Date: Thu, 7 Mar 2024 22:31:06 +0530 Subject: [PATCH] more feedback --- .../access_key_serialization.ts | 13 ++++++++++--- src/www/app/outline_server_repository/server.ts | 8 +++++--- src/www/app/tunnel.ts | 3 --- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/www/app/outline_server_repository/access_key_serialization.ts b/src/www/app/outline_server_repository/access_key_serialization.ts index 02aee6b481..760303850a 100644 --- a/src/www/app/outline_server_repository/access_key_serialization.ts +++ b/src/www/app/outline_server_repository/access_key_serialization.ts @@ -36,8 +36,16 @@ export function staticKeyToShadowsocksSessionConfig(staticKey: string): Shadowso } } -function parseShadowsocksSessionConfigJson(maybeJsonText: string): ShadowsocksSessionConfig | null { - const {method, password, server, server_port, prefix, error} = JSON.parse(maybeJsonText); +function parseShadowsocksSessionConfigJson( + maybeJsonText: string +): ShadowsocksSessionConfig | errors.SessionConfigError | null { + const responseJson = JSON.parse(maybeJsonText); + + if ('error' in responseJson) { + return responseJson.error; + } + + const {method, password, server, server_port, prefix} = responseJson; // These are the mandatory keys. const missingKeys = []; @@ -58,7 +66,6 @@ function parseShadowsocksSessionConfigJson(maybeJsonText: string): ShadowsocksSe host: server, port: server_port, prefix, - error }; } diff --git a/src/www/app/outline_server_repository/server.ts b/src/www/app/outline_server_repository/server.ts index 8cc9b6dd22..fa75125995 100644 --- a/src/www/app/outline_server_repository/server.ts +++ b/src/www/app/outline_server_repository/server.ts @@ -96,11 +96,13 @@ export class OutlineServer implements Server { async connect() { if (this.type === ServerType.DYNAMIC_CONNECTION) { - this.sessionConfig = await fetchShadowsocksSessionConfig(this.sessionConfigLocation); + const sessionConfigOrError = await fetchShadowsocksSessionConfig(this.sessionConfigLocation); - if ('error' in this.sessionConfig) { - this.errorMessageId = this.sessionConfig.error.message; + if ('error' in sessionConfigOrError) { + throw new errors.SessionConfigFetchFailed((sessionConfigOrError.error as errors.SessionConfigError).message); } + + this.sessionConfig = sessionConfigOrError; } try { diff --git a/src/www/app/tunnel.ts b/src/www/app/tunnel.ts index 39d41e0ab9..fc475e2a21 100644 --- a/src/www/app/tunnel.ts +++ b/src/www/app/tunnel.ts @@ -12,15 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -import * as errors from '../model/errors'; - export interface ShadowsocksSessionConfig { host?: string; port?: number; password?: string; method?: string; prefix?: string; - error?: errors.SessionConfigError; } export const enum TunnelStatus {