Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -10,11 +10,14 @@ export const fetchWeather = async (
|
||||
`http://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}`
|
||||
).then((response) => {
|
||||
if (response.status === 401) {
|
||||
myToast("You are not authorized to access this resource. Please check your API key.", "error");
|
||||
myToast(
|
||||
"You are not authorized to access this resource. Please check your API key. (Error: x4010)",
|
||||
"error"
|
||||
);
|
||||
} else if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
myToast("Error fetching location data: " + response.statusText, "error");
|
||||
myToast("Error fetching location data. (Error: x32)", "error");
|
||||
}
|
||||
});
|
||||
const lat = location[0].lat;
|
||||
|
@@ -4,5 +4,16 @@ import { myToast } from "./toastify";
|
||||
export const changeAPIcookie = (newApiKey: string) => {
|
||||
let apiKey15 = newApiKey.slice(0, 15);
|
||||
Cookies.set("apiKey", newApiKey);
|
||||
myToast("API key updated successfully!" + " " + "Your new API key: " + apiKey15 + "...", "success");
|
||||
if (Cookies.get("apiKey") === newApiKey) {
|
||||
myToast(
|
||||
"API key updated successfully!" +
|
||||
" " +
|
||||
"Your new API key: " +
|
||||
apiKey15 +
|
||||
"...",
|
||||
"success"
|
||||
);
|
||||
} else {
|
||||
myToast("Failed to update API key. (Error: x30)", "error");
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user