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.
This commit is contained in:
Travis Ralston 2019-06-07 13:14:43 -06:00
parent 41cbfe0d27
commit 758b3394a4

View file

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