Error handling (#121)

This commit is contained in:
Geometrically
2023-05-22 18:11:31 -07:00
committed by GitHub
parent 6014172046
commit 1b47eb71e1
36 changed files with 271 additions and 198 deletions

View File

@@ -1,5 +1,6 @@
import { add_project_from_version as installMod, check_installed } from '@/helpers/profile'
import { ofetch } from 'ofetch'
import { useFetch } from '@/helpers/fetch.js'
import { handleError } from '@/store/notifications.js'
export const releaseColor = (releaseType) => {
switch (releaseType) {
@@ -17,19 +18,20 @@ export const releaseColor = (releaseType) => {
export const installVersionDependencies = async (profile, version) => {
for (const dep of version.dependencies) {
if (dep.version_id) {
if (await check_installed(profile.path, dep.project_id)) continue
if (await check_installed(profile.path, dep.project_id).catch(handleError)) continue
await installMod(profile.path, dep.version_id)
} else {
if (await check_installed(profile.path, dep.project_id)) continue
const depVersions = await ofetch(
`https://api.modrinth.com/v2/project/${dep.project_id}/version`
if (await check_installed(profile.path, dep.project_id).catch(handleError)) continue
const depVersions = await useFetch(
`https://api.modrinth.com/v2/project/${dep.project_id}/version`,
'dependency versions'
)
const latest = depVersions.find(
(v) =>
v.game_versions.includes(profile.metadata.game_version) &&
v.loaders.includes(profile.metadata.loader)
)
await installMod(profile.path, latest.id)
await installMod(profile.path, latest.id).catch(handleError)
}
}
}