Errors: InputError, DownloadError (an OfflineError) and UnsupportedTargetError, each from a real call
{
"loadLeague(\"nfll\")": {
"name": "InputError",
"instanceof InputError": true,
"instanceof OfflineError": false,
"instanceof UnsupportedTargetError": false,
"message": "unknown league \"nfll\"; known leagues: aaf, ahl, cfb, cricket, echl, mbb, milb, mlb, nba, nbagl, ncaa_baseball, ncaa_mhockey, ncaa_softball, ncaa_whockey, nfl, nhl, ohl, phf, pwhl, qmjhl, soccer, ufl, usfl, ushl, wbb, whl, wnba, xfl"
},
"marks(\"KC\", \"nfl\", { full: true }) during an outage": {
"name": "DownloadError",
"instanceof InputError": false,
"instanceof OfflineError": true,
"instanceof UnsupportedTargetError": false,
"url": "https://sdv.nyc3.cdn.digitaloceanspaces.com/assets/public/manifest/marks.csv",
"status": 503,
"message": "manifest download failed: https://sdv.nyc3.cdn.digitaloceanspaces.com/assets/public/manifest/marks.csv answered 503"
},
"logoWatermarks([\"PHI\", \"KC\"], …) in Node": {
"name": "UnsupportedTargetError",
"instanceof InputError": false,
"instanceof OfflineError": false,
"instanceof UnsupportedTargetError": true,
"message": "logo watermarks needs a DOM: build it in the browser (onMount, $effect, an Astro client:only island), not during SSR"
}
}import {
DownloadError,
InputError,
OfflineError,
SdvplotError,
UnsupportedTargetError,
loadLeague,
marks,
} from "@sportsdataverse/sdvplot";
import { logoWatermarks } from "@sportsdataverse/sdvplot/chartjs";
const caught = async (f: () => unknown) => {
try {
await f();
return "no error";
} catch (e) {
if (!(e instanceof SdvplotError)) throw e;
return {
name: e.name,
"instanceof InputError": e instanceof InputError,
"instanceof OfflineError": e instanceof OfflineError,
"instanceof UnsupportedTargetError": e instanceof UnsupportedTargetError,
...(e instanceof DownloadError ? { url: e.url, status: e.status } : {}),
message: e.message,
};
}
};
// The only download in sdvplot is the full logo manifest; this fetch answers as a CDN outage would. Catch
// OfflineError (DownloadError is one) to fall back to the bundled marks.
const outage = async (): Promise<Response> => new Response("", { status: 503 });
{
// @ts-expect-error: the league is checked at compile time too
'loadLeague("nfll")': await caught(() => loadLeague("nfll")),
'marks("KC", "nfl", { full: true }) during an outage': await caught(() =>
marks("KC", "nfl", { full: true, fetch: outage }),
),
// the Chart.js image plugins build <img> elements: in Node (SSR) there is no DOM to build them in
'logoWatermarks(["PHI", "KC"], …) in Node': await caught(() =>
logoWatermarks(["PHI", "KC"], { league: "nfl" }),
),
};
Tags: node · errors · InputError · DownloadError · OfflineError · UnsupportedTargetError. All sdvplot examples.