@@ -20,7 +20,6 @@ import { logger } from "matrix-js-sdk/src/logger";
20
20
import { IClientWellKnown } from "matrix-js-sdk/src/matrix" ;
21
21
22
22
import { _t , UserFriendlyError } from "../languageHandler" ;
23
- import { makeType } from "./TypeUtils" ;
24
23
import SdkConfig from "../SdkConfig" ;
25
24
import { ValidatedServerConfig } from "./ValidatedServerConfig" ;
26
25
@@ -43,7 +42,7 @@ export default class AutoDiscoveryUtils {
43
42
* @param {string | Error } error The error to check
44
43
* @returns {boolean } True if the error is a liveliness error.
45
44
*/
46
- public static isLivelinessError ( error : string | Error ) : boolean {
45
+ public static isLivelinessError ( error ? : string | Error | null ) : boolean {
47
46
if ( ! error ) return false ;
48
47
return ! ! LIVELINESS_DISCOVERY_ERRORS . find ( ( e ) =>
49
48
typeof error === "string" ? e === error : e === error . message ,
@@ -197,7 +196,7 @@ export default class AutoDiscoveryUtils {
197
196
) : ValidatedServerConfig {
198
197
if ( ! discoveryResult || ! discoveryResult [ "m.homeserver" ] ) {
199
198
// This shouldn't happen without major misconfiguration, so we'll log a bit of information
200
- // in the log so we can find this bit of codee but otherwise tell teh user "it broke".
199
+ // in the log so we can find this bit of code but otherwise tell the user "it broke".
201
200
logger . error ( "Ended up in a state of not knowing which homeserver to connect to." ) ;
202
201
throw new UserFriendlyError ( "Unexpected error resolving homeserver configuration" ) ;
203
202
}
@@ -216,7 +215,7 @@ export default class AutoDiscoveryUtils {
216
215
// of Element.
217
216
let preferredIdentityUrl = defaultConfig && defaultConfig [ "isUrl" ] ;
218
217
if ( isResult && isResult . state === AutoDiscovery . SUCCESS ) {
219
- preferredIdentityUrl = isResult [ "base_url" ] ;
218
+ preferredIdentityUrl = isResult [ "base_url" ] ?? undefined ;
220
219
} else if ( isResult && isResult . state !== AutoDiscovery . PROMPT ) {
221
220
logger . error ( "Error determining preferred identity server URL:" , isResult ) ;
222
221
if ( isResult . state === AutoDiscovery . FAIL_ERROR ) {
@@ -244,6 +243,12 @@ export default class AutoDiscoveryUtils {
244
243
}
245
244
246
245
const preferredHomeserverUrl = hsResult [ "base_url" ] ;
246
+
247
+ if ( ! preferredHomeserverUrl ) {
248
+ logger . error ( "No homeserver URL configured" ) ;
249
+ throw new UserFriendlyError ( "Unexpected error resolving homeserver configuration" ) ;
250
+ }
251
+
247
252
let preferredHomeserverName = serverName ? serverName : hsResult [ "server_name" ] ;
248
253
249
254
const url = new URL ( preferredHomeserverUrl ) ;
@@ -255,14 +260,14 @@ export default class AutoDiscoveryUtils {
255
260
throw new UserFriendlyError ( "Unexpected error resolving homeserver configuration" ) ;
256
261
}
257
262
258
- return makeType ( ValidatedServerConfig , {
263
+ return {
259
264
hsUrl : preferredHomeserverUrl ,
260
265
hsName : preferredHomeserverName ,
261
266
hsNameIsDifferent : url . hostname !== preferredHomeserverName ,
262
267
isUrl : preferredIdentityUrl ,
263
268
isDefault : false ,
264
269
warning : hsResult . error ,
265
270
isNameResolvable : ! isSynthetic ,
266
- } ) ;
271
+ } as ValidatedServerConfig ;
267
272
}
268
273
}
0 commit comments