fix: correctly return error and bubble up when the api could not be reached

This commit is contained in:
kolaente 2024-04-21 23:33:50 +02:00
parent 324df991ce
commit 84197dd9c1
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
1 changed files with 7 additions and 4 deletions

View File

@ -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<boolean> {
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 {