fix: correctly return error and bubble up when the api could not be reached
This commit is contained in:
parent
324df991ce
commit
84197dd9c1
@ -1,5 +1,5 @@
|
|||||||
import {computed, reactive, toRefs} from 'vue'
|
import {computed, reactive, toRefs} from 'vue'
|
||||||
import {defineStore, acceptHMRUpdate} from 'pinia'
|
import {acceptHMRUpdate, defineStore} from 'pinia'
|
||||||
import {parseURL} from 'ufo'
|
import {parseURL} from 'ufo'
|
||||||
|
|
||||||
import {HTTPFactory} from '@/helpers/fetcher'
|
import {HTTPFactory} from '@/helpers/fetcher'
|
||||||
@ -7,6 +7,7 @@ import {objectToCamelCase} from '@/helpers/case'
|
|||||||
|
|
||||||
import type {IProvider} from '@/types/IProvider'
|
import type {IProvider} from '@/types/IProvider'
|
||||||
import type {MIGRATORS} from '@/views/migrate/migrators'
|
import type {MIGRATORS} from '@/views/migrate/migrators'
|
||||||
|
import {InvalidApiUrlProvidedError} from '@/helpers/checkAndSetApiUrl'
|
||||||
|
|
||||||
export interface ConfigState {
|
export interface ConfigState {
|
||||||
version: string,
|
version: string,
|
||||||
@ -83,15 +84,17 @@ export const useConfigStore = defineStore('config', () => {
|
|||||||
function setConfig(config: ConfigState) {
|
function setConfig(config: ConfigState) {
|
||||||
Object.assign(state, config)
|
Object.assign(state, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function update(): Promise<boolean> {
|
async function update(): Promise<boolean> {
|
||||||
const HTTP = HTTPFactory()
|
const HTTP = HTTPFactory()
|
||||||
const {data: config} = await HTTP.get('info')
|
const {data: config} = await HTTP.get('info')
|
||||||
|
|
||||||
if (typeof config.version === 'undefined') {
|
if (typeof config.version === 'undefined') {
|
||||||
return false
|
throw new InvalidApiUrlProvidedError()
|
||||||
}
|
}
|
||||||
|
|
||||||
setConfig(objectToCamelCase(config))
|
setConfig(objectToCamelCase(config))
|
||||||
const success = !!config
|
return !!config
|
||||||
return success
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user