Skip to content

Commit

Permalink
feat(client): add cause to custom error
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellacosse committed Apr 17, 2024
1 parent f00a94c commit a0ff397
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions client/src/www/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions client/src/www/model/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit a0ff397

Please sign in to comment.