Skip to content

Commit 2c3e7a8

Browse files
Improve error handling in loadRunnableListings for chapter-listings.json fetch
1 parent 8bbdf5a commit 2c3e7a8

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

EssentialCSharp.Web/wwwroot/js/trydotnet-module.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ function loadRunnableListings() {
5858

5959
_runnableListingsPromise = fetch('/js/chapter-listings.json')
6060
.then(res => {
61-
if (!res.ok) throw new Error(`Failed to load chapter-listings.json: ${res.status}`);
61+
if (!res.ok) {
62+
const msg = res.status === 404
63+
? 'chapter-listings.json not found (404). The NuGet content package may not be restored — Run buttons will not be shown.'
64+
: `Failed to load chapter-listings.json: ${res.status}`;
65+
throw new Error(msg);
66+
}
6267
return res.json();
6368
})
6469
.then(data => {
@@ -81,6 +86,7 @@ function loadRunnableListings() {
8186
})
8287
.catch(err => {
8388
console.warn('Could not load runnable listings:', err);
89+
_runnableListingsPromise = null; // Allow retry on next call (e.g. transient network error)
8490
return new Set(); // graceful degradation — no Run buttons
8591
});
8692

0 commit comments

Comments
 (0)