fix: throw error on fail so it doesnt cache (#5023)

* fix: throw error on fail so it doesnt cache

* lint

---------

Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
This commit is contained in:
Calum H.
2026-01-02 00:39:13 +00:00
committed by GitHub
parent daf804947c
commit fef6df1321

View File

@@ -7,7 +7,14 @@ export default defineCachedEventHandler(
const config = useRuntimeConfig(event)
const apiBaseUrl = config.apiBaseUrl || config.public.apiBaseUrl
return await $fetch<Labrinth.Tags.v2.GameVersion[]>(`${apiBaseUrl}tag/game_version`)
const response = await $fetch<Labrinth.Tags.v2.GameVersion[]>(`${apiBaseUrl}tag/game_version`)
// nitro wont cache if we throw an error
if (!response || !Array.isArray(response)) {
throw createError({ statusCode: 502, message: 'Invalid response from API' })
}
return response
},
{
maxAge: CACHE_MAX_AGE,