Refactor homeserver lookup code #12

Merged
bad merged 10 commits from refactor-homeserver-lookup into princess 2020-10-23 08:57:01 +00:00
1 changed files with 8 additions and 6 deletions
Showing only changes of commit 0c3c06bc0a - Show all commits

View File

@ -128,13 +128,15 @@ class Form extends ElemJS {
this.status(`Looking up homeserver... trying ${address}`) this.status(`Looking up homeserver... trying ${address}`)
// check if we found the actual matrix server // check if we found the actual matrix server
const versionsReq = await fetch(`${address}/_matrix/client/versions`).catch(()=>{}); try {
if(versionsReq?.ok) { const versionsReq = await fetch(`${address}/_matrix/client/versions`)
const versions = await versionsReq.json().catch(()=>{}) if(versionsReq.ok) {
if (Array.isArray(versions.versions)) { const versions = await versionsReq.json().catch(()=>{})
return address if (Array.isArray(versions.versions)) {
return address
}
} }
} } catch(e) {}
// find the next matrix server in the chain // find the next matrix server in the chain
const root = await fetch(`${address}/.well-known/matrix/client`).then(res => res.json()).catch(e => { const root = await fetch(`${address}/.well-known/matrix/client`).then(res => res.json()).catch(e => {