Skip to content

Commit

Permalink
more feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellacosse committed Mar 7, 2024
1 parent cf17514 commit 2e1db31
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
13 changes: 10 additions & 3 deletions src/www/app/outline_server_repository/access_key_serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -58,7 +66,6 @@ function parseShadowsocksSessionConfigJson(maybeJsonText: string): ShadowsocksSe
host: server,
port: server_port,
prefix,
error
};
}

Expand Down
8 changes: 5 additions & 3 deletions src/www/app/outline_server_repository/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions src/www/app/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2e1db31

Please sign in to comment.