Skip to content
Snippets Groups Projects
Verified Commit 00c53294 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame :jack_o_lantern:
Browse files

fixup! Bug 27476: Implement about:torconnect captive portal within Tor Browser

Bug 42479: Improve TorConnect error handling.

Consume the new error codes and transform them into localized error
messages.
parent 04fbc3dc
Branches
Tags
1 merge request!968Draft: Bug 42479: Improve TorConnect error handling
......@@ -37,10 +37,9 @@ export class TorConnectParent extends JSWindowActorParent {
State: TorConnect.state,
StateChanged: false,
PreviousState: TorConnectState.Initial,
ErrorMessage: TorConnect.errorMessage,
ErrorCode: TorConnect.errorCode,
ErrorDetails: TorConnect.errorDetails,
BootstrapProgress: TorConnect.bootstrapProgress,
BootstrapStatus: TorConnect.bootstrapStatus,
InternetStatus: TorConnect.internetStatus,
DetectedLocation: TorConnect.detectedLocation,
ShowViewLog: TorConnect.logHasWarningOrError,
......@@ -79,15 +78,16 @@ export class TorConnectParent extends JSWindowActorParent {
self.state.StateChanged = true;
// Clear any previous error information if we are bootstrapping.
if (self.state.State === TorConnectState.Bootstrapping) {
self.state.ErrorMessage = null;
self.state.ErrorCode = null;
self.state.ErrorDetails = null;
}
self.state.BootstrapProgress = TorConnect.bootstrapProgress;
self.state.ShowViewLog = TorConnect.logHasWarningOrError;
self.state.HasEverFailed = TorConnect.hasEverFailed;
break;
}
case TorConnectTopics.BootstrapProgress: {
self.state.BootstrapProgress = obj.progress;
self.state.BootstrapStatus = obj.status;
self.state.ShowViewLog = obj.hasWarnings;
break;
}
......@@ -96,7 +96,7 @@ export class TorConnectParent extends JSWindowActorParent {
break;
}
case TorConnectTopics.BootstrapError: {
self.state.ErrorMessage = obj.message;
self.state.ErrorCode = obj.code;
self.state.ErrorDetails = obj.details;
self.state.InternetStatus = TorConnect.internetStatus;
self.state.DetectedLocation = TorConnect.detectedLocation;
......
......@@ -347,6 +347,56 @@ class AboutTorConnect {
this.elements.breadcrumbContainer.classList.add("hidden");
}
getLocalizedStatus(status) {
const aliases = {
conn_dir: "conn",
handshake_dir: "onehop_create",
conn_or: "enough_dirinfo",
handshake_or: "ap_conn",
};
if (status in aliases) {
status = aliases[status];
}
return TorStrings.torConnect.bootstrapStatus[status] ?? status;
}
getMaybeLocalizedError(state) {
switch (state.ErrorCode) {
case "Offline":
return TorStrings.torConnect.offline;
case "BootstrapError": {
const details = state.ErrorDetails?.details;
if (!details || !details.phase || !details.reason) {
return TorStrings.torConnect.torBootstrapFailed;
}
let status = this.getLocalizedStatus(details.phase);
const reason =
TorStrings.torConnect.bootstrapWarning[details.reason] ??
details.reason;
return TorStrings.torConnect.bootstrapFailedDetails
.replace("%1$S", status)
.replace("%2$S", reason);
}
case "CannotDetermineCountry":
return TorStrings.torConnect.cannotDetermineCountry;
case "NoSettingsForCountry":
return TorStrings.torConnect.noSettingsForCountry;
case "AllSettingsFailed":
return TorStrings.torConnect.autoBootstrappingAllFailed;
case "ExternaError":
// A standard JS error, or something for which we do probably do not
// have a translation. Returning the original message is the best we can
// do.
return state.ErrorDetails.message;
default:
console.warn(
`Unknown error code: ${state.ErrorCode}`,
state.ErrorDetails
);
return state.ErrorDetails?.message ?? state.ErrorCode;
}
}
/*
These methods update the UI based on the current TorConnect state
*/
......@@ -524,7 +574,7 @@ class AboutTorConnect {
showConnectionAssistant(state) {
this.setTitle(TorStrings.torConnect.couldNotConnect, "assist");
this.showConfigureConnectionLink(TorStrings.torConnect.assistDescription);
this.setProgress(state?.ErrorDetails, false);
this.setProgress(this.getMaybeLocalizedError(state), false);
this.setBreadcrumbsStatus(
BreadcrumbStatus.Default,
BreadcrumbStatus.Active,
......@@ -544,7 +594,7 @@ class AboutTorConnect {
this.showConfigureConnectionLink(
TorStrings.torConnect.errorLocationDescription
);
this.setProgress(state.ErrorMessage, false);
this.setProgress(TorStrings.torConnect.cannotDetermineCountry, false);
this.setBreadcrumbsStatus(
BreadcrumbStatus.Default,
BreadcrumbStatus.Active,
......@@ -564,7 +614,7 @@ class AboutTorConnect {
this.showConfigureConnectionLink(
TorStrings.torConnect.isLocationCorrectDescription
);
this.setProgress(state.ErrorMessage, false);
this.setProgress(this.getMaybeLocalizedError(state), false);
this.setBreadcrumbsStatus(
BreadcrumbStatus.Default,
BreadcrumbStatus.Default,
......@@ -582,7 +632,7 @@ class AboutTorConnect {
showFinalError(state) {
this.setTitle(TorStrings.torConnect.finalError, "final");
this.setLongText(TorStrings.torConnect.finalErrorDescription);
this.setProgress(state ? state.ErrorDetails : "", false);
this.setProgress(state ? this.getMaybeLocalizedError(state) : "", false);
this.setBreadcrumbsStatus(
BreadcrumbStatus.Default,
BreadcrumbStatus.Default,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment