diff --git a/src/hooks/wallpaper/useWallpaper.ts b/src/hooks/wallpaper/useWallpaper.ts index c8ed5fa..ac3ac06 100644 --- a/src/hooks/wallpaper/useWallpaper.ts +++ b/src/hooks/wallpaper/useWallpaper.ts @@ -1,7 +1,10 @@ -import { SweatherErrorCode } from '@/logic/error'; -import { getLocalBackground, getLocationBackground } from '@/services/wallpaper'; -import { Uri } from '@/services/wallpaper/types'; -import { useEffect, useState } from 'react'; +import { SweatherErrorCode } from "@/logic/error"; +import { + getLocalBackground, + getLocationBackground, +} from "@/services/wallpaper"; +import { Uri } from "@/services/wallpaper/types"; +import { useEffect, useState } from "react"; export default function useWallpaper(location?: string) { const [wallpaper, setWallpaper] = useState(); @@ -20,21 +23,23 @@ export default function useWallpaper(location?: string) { const uri = await getLocationBackground({ query: location, - }) + }); if (uri) { - setWallpaper(uri) - setError(null) + setWallpaper(uri); + setError(null); + } else { + throw new Error(`No wallpaper found for ${location}`); } } catch (error) { - console.error("Unable to retrieve wallpaper from location"); + console.error("Unable to retrieve wallpaper from location", error); setError(SweatherErrorCode.WALLPAPER_SERVICE_ERROR); setWallpaper(getLocalBackground()); } finally { setLoading(false); } - } + }; loadWallpaper(); }, [location]);