res.json type fixes

This commit is contained in:
Cadence Ember
2025-12-01 16:03:27 +13:00
parent 6d0a98eb49
commit 20453aab43
3 changed files with 4 additions and 6 deletions

View File

@@ -50,11 +50,6 @@ let {reg, getTemplateRegistration, writeRegistration, readRegistration, checkReg
const {setupEmojis} = require("../src/m2d/actions/setup-emojis") const {setupEmojis} = require("../src/m2d/actions/setup-emojis")
function die(message) {
console.error(message)
process.exit(1)
}
async function suggestWellKnown(serverUrlPrompt, url, otherwise) { async function suggestWellKnown(serverUrlPrompt, url, otherwise) {
try { try {
var json = await fetch(`${url}/.well-known/matrix/client`).then(res => res.json()) var json = await fetch(`${url}/.well-known/matrix/client`).then(res => res.json())
@@ -80,6 +75,7 @@ async function validateHomeserverOrigin(serverUrlPrompt, url) {
return e.message return e.message
} }
try { try {
/** @type {any} */
var json = await res.json() var json = await res.json()
if (!Array.isArray(json?.versions) || !json.versions.includes("v1.11")) { if (!Array.isArray(json?.versions) || !json.versions.includes("v1.11")) {
return `OOYE needs Matrix version v1.11, but ${url} doesn't support this` return `OOYE needs Matrix version v1.11, but ${url} doesn't support this`

View File

@@ -22,6 +22,7 @@ async function fetchMessage(messageID) {
throw new Error(`Failed to connect to PK API: ${networkError.toString()}`) throw new Error(`Failed to connect to PK API: ${networkError.toString()}`)
} }
if (!res.ok) throw new Error(`PK API returned an error: ${await res.text()}`) if (!res.ok) throw new Error(`PK API returned an error: ${await res.text()}`)
/** @type {any} */
const root = await res.json() const root = await res.json()
if (!root.member) throw new Error(`PK API didn't return member data: ${JSON.stringify(root)}`) if (!root.member) throw new Error(`PK API didn't return member data: ${JSON.stringify(root)}`)
return root return root

View File

@@ -72,6 +72,7 @@ async function mreq(method, url, bodyIn, extra = {}) {
}, extra) }, extra)
const res = await fetch(baseUrl + url, opts) const res = await fetch(baseUrl + url, opts)
/** @type {any} */
const root = await res.json() const root = await res.json()
if (!res.ok || root.errcode) { if (!res.ok || root.errcode) {