2023-05-22 18:11:31 -07:00
|
|
|
import { ofetch } from 'ofetch'
|
|
|
|
|
import { handleError } from '@/store/state.js'
|
2023-06-20 22:03:59 -04:00
|
|
|
import { getVersion } from '@tauri-apps/api/app'
|
2023-05-22 18:11:31 -07:00
|
|
|
|
|
|
|
|
export const useFetch = async (url, item) => {
|
|
|
|
|
try {
|
2023-06-20 22:03:59 -04:00
|
|
|
const version = await getVersion()
|
|
|
|
|
|
2023-06-19 14:59:06 -07:00
|
|
|
return await ofetch(url, {
|
2023-06-20 22:03:59 -04:00
|
|
|
headers: { 'User-Agent': `modrinth/theseus/${version} (support@modrinth.com)` },
|
2023-06-19 14:59:06 -07:00
|
|
|
})
|
2023-05-22 18:11:31 -07:00
|
|
|
} catch (err) {
|
|
|
|
|
handleError({ message: `Error fetching ${item}` })
|
2023-06-02 07:09:46 -07:00
|
|
|
console.error(err)
|
2023-05-22 18:11:31 -07:00
|
|
|
}
|
|
|
|
|
}
|