Replace newTranslatableError
with UserFriendlyError
(#10440
* Introduce UserFriendlyError * Replace newTranslatableError with UserFriendlyError * Remove ITranslatableError * Fix up some strict lints * Document when we/why we can remove * Update matrix-web-i18n Includes changes to find `new UserFriendlyError`, see https://github.com/matrix-org/matrix-web-i18n/pull/6 * Include room ID in error * Translate fallback error * Translate better * Update i18n strings * Better re-use * Minor comment fixes
This commit is contained in:
parent
567248d5c5
commit
ff1468b6d3
10 changed files with 285 additions and 99 deletions
|
@ -19,7 +19,7 @@ import { AutoDiscovery, ClientConfig } from "matrix-js-sdk/src/autodiscovery";
|
|||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { IClientWellKnown } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { _t, _td, newTranslatableError } from "../languageHandler";
|
||||
import { _t, UserFriendlyError } from "../languageHandler";
|
||||
import { makeType } from "./TypeUtils";
|
||||
import SdkConfig from "../SdkConfig";
|
||||
import { ValidatedServerConfig } from "./ValidatedServerConfig";
|
||||
|
@ -147,7 +147,7 @@ export default class AutoDiscoveryUtils {
|
|||
syntaxOnly = false,
|
||||
): Promise<ValidatedServerConfig> {
|
||||
if (!homeserverUrl) {
|
||||
throw newTranslatableError(_td("No homeserver URL provided"));
|
||||
throw new UserFriendlyError("No homeserver URL provided");
|
||||
}
|
||||
|
||||
const wellknownConfig: IClientWellKnown = {
|
||||
|
@ -199,7 +199,7 @@ export default class AutoDiscoveryUtils {
|
|||
// This shouldn't happen without major misconfiguration, so we'll log a bit of information
|
||||
// in the log so we can find this bit of codee but otherwise tell teh user "it broke".
|
||||
logger.error("Ended up in a state of not knowing which homeserver to connect to.");
|
||||
throw newTranslatableError(_td("Unexpected error resolving homeserver configuration"));
|
||||
throw new UserFriendlyError("Unexpected error resolving homeserver configuration");
|
||||
}
|
||||
|
||||
const hsResult = discoveryResult["m.homeserver"];
|
||||
|
@ -221,9 +221,9 @@ export default class AutoDiscoveryUtils {
|
|||
logger.error("Error determining preferred identity server URL:", isResult);
|
||||
if (isResult.state === AutoDiscovery.FAIL_ERROR) {
|
||||
if (AutoDiscovery.ALL_ERRORS.indexOf(isResult.error as string) !== -1) {
|
||||
throw newTranslatableError(isResult.error as string);
|
||||
throw new UserFriendlyError(String(isResult.error));
|
||||
}
|
||||
throw newTranslatableError(_td("Unexpected error resolving identity server configuration"));
|
||||
throw new UserFriendlyError("Unexpected error resolving identity server configuration");
|
||||
} // else the error is not related to syntax - continue anyways.
|
||||
|
||||
// rewrite homeserver error since we don't care about problems
|
||||
|
@ -237,9 +237,9 @@ export default class AutoDiscoveryUtils {
|
|||
logger.error("Error processing homeserver config:", hsResult);
|
||||
if (!syntaxOnly || !AutoDiscoveryUtils.isLivelinessError(hsResult.error)) {
|
||||
if (AutoDiscovery.ALL_ERRORS.indexOf(hsResult.error as string) !== -1) {
|
||||
throw newTranslatableError(hsResult.error as string);
|
||||
throw new UserFriendlyError(String(hsResult.error));
|
||||
}
|
||||
throw newTranslatableError(_td("Unexpected error resolving homeserver configuration"));
|
||||
throw new UserFriendlyError("Unexpected error resolving homeserver configuration");
|
||||
} // else the error is not related to syntax - continue anyways.
|
||||
}
|
||||
|
||||
|
@ -252,7 +252,7 @@ export default class AutoDiscoveryUtils {
|
|||
// It should have been set by now, so check it
|
||||
if (!preferredHomeserverName) {
|
||||
logger.error("Failed to parse homeserver name from homeserver URL");
|
||||
throw newTranslatableError(_td("Unexpected error resolving homeserver configuration"));
|
||||
throw new UserFriendlyError("Unexpected error resolving homeserver configuration");
|
||||
}
|
||||
|
||||
return makeType(ValidatedServerConfig, {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue