← Statpro dev log

News cards got faces, and the feed survives bad data

#web#product#data#solo-founder

Four news cards in a row, three with glowing round portraits and small badges and one with an empty dashed circle, while a coral item sits set aside below.

One malformed news item used to take down the whole news page. The cards on that page were also plain text: a headline, a byline and a timestamp. I fixed both on Statpro, a sports stats site, in the same pass, because adding pictures meant trusting more data.

The news page is a feed of short player news cards, each about one player. Its items come from outside sources I don't control, so any field can arrive missing or wrong.

Faces with fallbacks

Each card now shows the player's headshot with a small team logo badge. Every image has a fallback. If the headshot fails, the card shows initials. If the logo fails, it shows the three-letter team code. A card never shows a broken image.

Verify before you decorate

Before a card gets a headshot or a link, its player is checked against my shared reference data of known players. An unverified player still appears in the feed, just without a photo or a link. This is the check, simplified:

const verified = playerId !== null && verifiedPlayers.has(playerKey);

return {
  ...item,
  player: {
    ...item.player,
    href: verified ? referencePath(item.league, "players", slug) : null,
    imageUrl: verified ? safeMediaUrl(headshotUrl) : null,
  },
};

Decoration runs on the server and fails closed. If the database is unreachable, the items go out undecorated with no links. Better plain text than a link to a 404.

Quarantine before you crash

The page used to treat a batch of news as all or nothing, so one bad item threw and killed everything. Now a failure is caught per item and set aside, with its error code and the field that broke. If 8 of 10 items are good, readers get those 8. Zero good items still throws, because an empty feed should fail loudly.

The pattern works for any page built from data you don't control: verify before you decorate, quarantine before you crash.

This is the build log for Statpro (statpro.io) · All entries · Weekly essays