mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-09-17 16:46:24 +00:00
fix(jobbank-search): degrade an unparseable pubDate to a null date instead of crashing the search (#416) (#417)
new Date(<unparseable>) yields an Invalid Date whose toISOString()
throws RangeError, and normalizeSearchItem runs inside an unguarded
items.map(), so one malformed RSS item killed the entire search with
{"error": "Invalid Date", "code": "API_ERROR"} and exit 1. The
un-CDATA'd fallback capture in parseRssItems can deliver exactly such a
value. An unparseable pubDate now degrades to the same shape as an
absent one (posted "", date null); every other item survives. Three
new cases pin the malformed shapes, each failing on the unfixed code.
This commit is contained in:
@@ -5,7 +5,13 @@ import { rssFetch, fetchWithUA, writeError, parseRssDescription, extractJobIdFro
|
||||
export function normalizeSearchItem(item: RssItem): Record<string, unknown> {
|
||||
const parsed = parseRssDescription(item.description)
|
||||
const id = extractJobIdFromUrl(item.link)
|
||||
const posted = item.pubDate ? new Date(item.pubDate).toISOString() : ""
|
||||
// Guard the parse: new Date(<unparseable>) is an Invalid Date whose
|
||||
// toISOString() throws RangeError, and this runs inside an unguarded
|
||||
// items.map() - one bad feed item would kill the whole search as
|
||||
// API_ERROR (#416). An unparseable pubDate degrades to the same shape
|
||||
// as an absent one: posted "", date null.
|
||||
const parsedDate = item.pubDate ? new Date(item.pubDate) : null
|
||||
const posted = parsedDate && !Number.isNaN(parsedDate.getTime()) ? parsedDate.toISOString() : ""
|
||||
return {
|
||||
id,
|
||||
title: item.title,
|
||||
|
||||
Reference in New Issue
Block a user