Skip to content

Commit ddaa4a0

Browse files
Merge pull request #2 from CodeSignal/bugfix/fix-answers-404-error-handling
Fix: Handle 404 responses properly when loading answers.json
2 parents 7227388 + b2a2f6f commit ddaa4a0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@
7272
return {};
7373
}),
7474
fetch('/answers.json')
75-
.then(response => response.json())
75+
.then(response => {
76+
if (!response.ok) {
77+
// If file doesn't exist (404) or other error, return empty object
78+
return {};
79+
}
80+
return response.json();
81+
})
7682
.catch(() => ({}))
7783
])
7884
.then(([surveyJson, persistedAnswers]) => {

0 commit comments

Comments
 (0)