diff --git a/src/utils/queryHooks/instance.ts b/src/utils/queryHooks/instance.ts index 253b02ac..fe50d354 100644 --- a/src/utils/queryHooks/instance.ts +++ b/src/utils/queryHooks/instance.ts @@ -9,13 +9,22 @@ export type QueryKeyInstance = ['Instance'] | ['Instance', { domain?: string }] const queryFunction = async ({ queryKey }: QueryFunctionContext) => { const domain = queryKey[1]?.domain + + const checkV2Format = (body: Mastodon.Instance_V2) => { + if (body.version) { + return body + } else { + throw new Error('Instance v2 format error') + } + } + if (domain) { return await apiGeneral>({ method: 'get', domain, url: 'api/v2/instance' }) - .then(res => res.body) + .then(res => checkV2Format(res.body)) .catch( async () => await apiGeneral>({ @@ -32,7 +41,7 @@ const queryFunction = async ({ queryKey }: QueryFunctionContext res.body) + .then(res => checkV2Format(res.body)) .catch( async () => await apiInstance>({