From 84197dd9c14b7f016bad452f8d529b32f593683c Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 21 Apr 2024 23:33:50 +0200 Subject: [PATCH] fix: correctly return error and bubble up when the api could not be reached --- frontend/src/stores/config.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/src/stores/config.ts b/frontend/src/stores/config.ts index eb09372da..05813a7e3 100644 --- a/frontend/src/stores/config.ts +++ b/frontend/src/stores/config.ts @@ -1,5 +1,5 @@ import {computed, reactive, toRefs} from 'vue' -import {defineStore, acceptHMRUpdate} from 'pinia' +import {acceptHMRUpdate, defineStore} from 'pinia' import {parseURL} from 'ufo' import {HTTPFactory} from '@/helpers/fetcher' @@ -7,6 +7,7 @@ import {objectToCamelCase} from '@/helpers/case' import type {IProvider} from '@/types/IProvider' import type {MIGRATORS} from '@/views/migrate/migrators' +import {InvalidApiUrlProvidedError} from '@/helpers/checkAndSetApiUrl' export interface ConfigState { version: string, @@ -83,15 +84,17 @@ export const useConfigStore = defineStore('config', () => { function setConfig(config: ConfigState) { Object.assign(state, config) } + async function update(): Promise { const HTTP = HTTPFactory() const {data: config} = await HTTP.get('info') + if (typeof config.version === 'undefined') { - return false + throw new InvalidApiUrlProvidedError() } + setConfig(objectToCamelCase(config)) - const success = !!config - return success + return !!config } return {