Don't handle identity server liveliness errors as fatal

An invalid IS causes an invalid HS, so we switch the order of the checks. Additionally, we adjust the HS result so that it appears like a liveliness error for the IS, allowing the app to continue normally.
pull/21833/head
Travis Ralston 2019-06-07 13:14:43 -06:00
parent 41cbfe0d27
commit 758b3394a4
1 changed files with 22 additions and 10 deletions

View File

@ -148,22 +148,16 @@ export default class AutoDiscoveryUtils {
}
const hsResult = discoveryResult['m.homeserver'];
if (hsResult.state !== AutoDiscovery.SUCCESS) {
console.error("Error processing homeserver config:", hsResult);
if (!syntaxOnly || !AutoDiscoveryUtils.isLivelinessError(hsResult.error)) {
if (AutoDiscovery.ALL_ERRORS.indexOf(hsResult.error) !== -1) {
throw newTranslatableError(hsResult.error);
}
throw newTranslatableError(_td("Unexpected error resolving homeserver configuration"));
} // else the error is not related to syntax - continue anyways.
}
const isResult = discoveryResult['m.identity_server'];
// Validate the identity server first because an invalid identity server causes
// and invalid homeserver, which may not be picked up correctly.
// Note: In the cases where we rely on this pre-populated "https://vector.im" (namely
// lack of identity server provided by the discovery method), we intentionally do not
// validate it. We already know the IS is an IS, and this helps some off-the-grid usage
// of Riot.
let preferredIdentityUrl = "https://vector.im";
const isResult = discoveryResult['m.identity_server'];
if (isResult && isResult.state === AutoDiscovery.SUCCESS) {
preferredIdentityUrl = isResult["base_url"];
} else if (isResult && isResult.state !== AutoDiscovery.PROMPT) {
@ -174,6 +168,24 @@ export default class AutoDiscoveryUtils {
}
throw newTranslatableError(_td("Unexpected error resolving identity server configuration"));
} // else the error is not related to syntax - continue anyways.
// rewrite homeserver error if we don't care about problems
if (syntaxOnly) {
hsResult.error = AutoDiscovery.ERROR_INVALID_IDENTITY_SERVER;
// Also use the user's supplied identity server if provided
if (isResult["base_url"]) preferredIdentityUrl = isResult["base_url"];
}
}
if (hsResult.state !== AutoDiscovery.SUCCESS) {
console.error("Error processing homeserver config:", hsResult);
if (!syntaxOnly || !AutoDiscoveryUtils.isLivelinessError(hsResult.error)) {
if (AutoDiscovery.ALL_ERRORS.indexOf(hsResult.error) !== -1) {
throw newTranslatableError(hsResult.error);
}
throw newTranslatableError(_td("Unexpected error resolving homeserver configuration"));
} // else the error is not related to syntax - continue anyways.
}
const preferredHomeserverUrl = hsResult["base_url"];