Skip to content

Commit

Permalink
feat(www): enable providers to send custom error responses via the dy…
Browse files Browse the repository at this point in the history
…namic key (#1830)

* proposal: add a provider message and contact option in the dynamic key

* style/logic cleanup

* revert model changes

* fix error pass through

* error is optional

* update model and error handling

* missed these imports

* I think that's it

* revert cleanup

* revert message changes from UI

* Update access_key_serialization.ts

* Update index.ts

* Update style.css

* Update index.ts

* more feedback

* revert UI

* finish revert

* revert list item

* feedback

* don't need this anymore either

* restore SessionConfigError

* don't wrap sessionconfigerror
  • Loading branch information
daniellacosse authored Mar 13, 2024
1 parent 8ec1aae commit 70df767
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GOBIND=env PATH="$(GOBIN):$(PATH)" "$(GOMOBILE)" bind
IMPORT_HOST=github.com
IMPORT_PATH=$(IMPORT_HOST)/Jigsaw-Code/outline-client

.PHONY: android apple linux windows
.PHONY: android apple linux windows browser

all: android apple linux windows

Expand Down Expand Up @@ -73,3 +73,6 @@ $(XGO): go.mod
go.mod: tools.go
go mod tidy
touch go.mod

browser:
echo 'browser environment: nothing to do'
2 changes: 2 additions & 0 deletions src/www/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ export class App {
buttonHandler = () => {
this.showErrorDetailDialog(error);
};
} else if (error instanceof errors.SessionConfigError) {
toastMessage = error.message;
} else {
const hasErrorDetails = Boolean(error.message || error.cause);
toastMessage = this.localize('error-unexpected');
Expand Down
14 changes: 12 additions & 2 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,14 @@ export function staticKeyToShadowsocksSessionConfig(staticKey: string): Shadowso
}
}

function parseShadowsocksSessionConfigJson(maybeJsonText: string): ShadowsocksSessionConfig | null {
const {method, password, server, server_port, prefix} = JSON.parse(maybeJsonText);
function parseShadowsocksSessionConfigJson(responseBody: string): ShadowsocksSessionConfig | null {
const responseJson = JSON.parse(responseBody);

if ('error' in responseJson) {
throw new errors.SessionConfigError(responseJson.error.message);
}

const {method, password, server, server_port, prefix} = responseJson;

// These are the mandatory keys.
const missingKeys = [];
Expand Down Expand Up @@ -80,6 +86,10 @@ export async function fetchShadowsocksSessionConfig(configLocation: URL): Promis

return parseShadowsocksSessionConfigJson(responseBody);
} catch (cause) {
if (cause instanceof errors.SessionConfigError) {
throw cause;
}

throw new errors.ServerAccessKeyInvalid('Failed to parse VPN information fetched from dynamic access key.', {
cause,
});
Expand Down
6 changes: 6 additions & 0 deletions src/www/model/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export class SessionConfigFetchFailed extends CustomError {
}
}

export class SessionConfigError extends CustomError {
constructor(message: string) {
super(message);
}
}

export class ServerAccessKeyInvalid extends CustomError {
constructor(message: string, options?: {cause?: Error}) {
super(message, options);
Expand Down

0 comments on commit 70df767

Please sign in to comment.