Refactor homeserver lookup code #12
1 changed files with 8 additions and 6 deletions
|
@ -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`)
|
||||||
|
if(versionsReq.ok) {
|
||||||
const versions = await versionsReq.json().catch(()=>{})
|
const versions = await versionsReq.json().catch(()=>{})
|
||||||
if (Array.isArray(versions.versions)) {
|
if (Array.isArray(versions.versions)) {
|
||||||
return address
|
return address
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch(e) {}
|
||||||
|
|
||||||
// find the next matrix server in the chain
|
// find the next matrix server in the chain
|
||||||
bad marked this conversation as resolved
Outdated
|
|||||||
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 => {
|
||||||
|
|
Loading…
Reference in a new issue
Why chain a promise catch here? I don't have a problem with promise chaining, it's just weird considering that we used the try/catch syntax 3 lines up. IMO they should be made consistent?
It was shorter. I actually wanted to write the code like it's written now but jshint errored on the optional chain. It's fixed now