Skip to content

Commit

Permalink
Fix bug requesting weather when the location does not have an associa…
Browse files Browse the repository at this point in the history
…ted wallpaper
  • Loading branch information
mgonzalezg9 committed May 18, 2024
1 parent d280078 commit 4dc9f92
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/hooks/wallpaper/useWallpaper.ts
Original file line number Diff line number Diff line change
@@ -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<Uri>();
Expand All @@ -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]);
Expand Down

0 comments on commit 4dc9f92

Please sign in to comment.