Skip to content

Commit

Permalink
Add fix for stale NWS data (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Oct 13, 2023
1 parent f57d378 commit d97d0de
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/features/weather/weatherSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import type { RootState } from "../../store";
import { AppDispatch } from "../../store";
import * as nwsWeather from "../../services/nwsWeather";
import { differenceInMinutes } from "date-fns";
import { differenceInMinutes, isPast } from "date-fns";
import * as timezoneService from "../../services/timezone";
import * as aviationWeatherService from "../../services/aviationWeather";
import * as elevationService from "../../services/elevation";
Expand Down Expand Up @@ -632,6 +632,14 @@ export const getWeather =
try {
const windsAloft = await rapidRefresh.getWindsAloft(lat, lon);

if (
windsAloft.hours.filter(({ date }) => !isPast(new Date(date)))
.length < 10
) {
console.info("Stale NWS rapid refresh data");
throw new Error("Rapid Refresh is too old");
}

if (isStale()) return;

dispatch(windsAloftReceived(windsAloft));
Expand Down

0 comments on commit d97d0de

Please sign in to comment.