Skip to content

Commit f1ef047

Browse files
YAMRAJ13yclaude
andcommitted
fix(noaa): severe weather always reported zero — /alerts/active rejects limit
`getActiveAlerts()` always sent `limit` to `api.weather.gov/alerts/active`, which the endpoint does not accept. The upstream reply is explicit: HTTP 400 {"parameter": "query.limit", "message": "Query parameter \"limit\" is not recognized"} `safeFetch` resolves to `{ error }` rather than throwing, so `alerts?.features || []` collapsed to an empty array and the source reported a confident all-clear on every sweep since the parameter was added: "totalSevereAlerts": 0, "summary": { "hurricanes": 0, "tornadoes": 0, "floods": 0, "winterStorms": 0, "wildfires": 0, "other": 0 } with no error field anywhere in the payload. At the time of this commit the same query without `limit` returns 33 active severe alerts, including a live Severe Thunderstorm Warning and 26 Extreme Heat Warnings. Drop the parameter. `/alerts/active` only ever returns currently-active alerts, so the response is naturally bounded and no client-side cap is needed — capping would under-report `totalSevereAlerts` during exactly the severe-weather outbreaks this source exists to catch. Also pass through `alerts.error` so a future upstream failure is visible in the payload instead of silently rendering as "no severe weather anywhere in the US". Same bug class, four lines; happy to split it out if preferred. Verified: 0 -> 33 alerts against the live API; forced-failure path now surfaces the error; `node --test test/*.test.mjs` 45 pass / 1 skipped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 3db7068 commit f1ef047

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

apis/sources/noaa.mjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ export async function getActiveAlerts(opts = {}) {
1111
severity = null, // Extreme, Severe, Moderate, Minor
1212
urgency = null, // Immediate, Expected, Future
1313
event = null, // e.g. "Tornado Warning", "Hurricane Warning"
14-
limit = 50,
1514
} = opts;
1615

17-
const params = new URLSearchParams({ limit: String(limit), status: 'actual' });
16+
// /alerts/active does not accept `limit` — sending it fails the whole request
17+
// with HTTP 400 ("Query parameter \"limit\" is not recognized"). The endpoint
18+
// only returns currently-active alerts, so the response is naturally bounded.
19+
const params = new URLSearchParams({ status: 'actual' });
1820
if (severity) params.set('severity', severity);
1921
if (urgency) params.set('urgency', urgency);
2022
if (event) params.set('event', event);
@@ -48,6 +50,10 @@ export async function briefing() {
4850
return {
4951
source: 'NOAA/NWS',
5052
timestamp: new Date().toISOString(),
53+
// Surface upstream failures rather than reporting a confident all-clear.
54+
// safeFetch resolves to { error } instead of throwing, so without this a
55+
// failed request looks identical to "no severe weather anywhere in the US".
56+
...(alerts?.error ? { error: alerts.error } : {}),
5157
totalSevereAlerts: features.length,
5258
summary: {
5359
hurricanes: hurricanes.length,

0 commit comments

Comments
 (0)