Files
Modrinth-plus/apps/app-frontend/src/helpers/fetch.js

20 lines
593 B
JavaScript
Raw Normal View History

import { injectNotificationManager } from '@modrinth/ui'
import { getVersion } from '@tauri-apps/api/app'
import { fetch } from '@tauri-apps/plugin-http'
2023-05-22 18:11:31 -07:00
export const useFetch = async (url, item, isSilent) => {
2023-05-22 18:11:31 -07:00
try {
const version = await getVersion()
return await fetch(url, {
method: 'GET',
headers: { 'User-Agent': `modrinth/theseus/${version} (support@modrinth.com)` },
})
2023-05-22 18:11:31 -07:00
} catch (err) {
if (!isSilent) {
const { handleError } = injectNotificationManager()
handleError({ message: `Error fetching ${item}` })
}
console.error(err)
2023-05-22 18:11:31 -07:00
}
}