Skip to content

Commit eed7bc7

Browse files
fix: Add HTTP status checks before JSON parsing in tests
1 parent 7900fbf commit eed7bc7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ <h2>📊 Overall Status</h2>
164164

165165
try {
166166
const response = await fetch(`${API_URL}/FRED-GDP?mode=latest`);
167+
if (!response.ok) {
168+
resultDiv.className = 'result error';
169+
resultDiv.textContent = `❌ HTTP ${response.status}: ${response.statusText}\nURL: ${response.url}`;
170+
testResults['api'] = false;
171+
updateOverallStatus();
172+
return;
173+
}
167174
const data = await response.json();
168175

169176
testResults['api'] = response.status === 200 || response.status === 401;
@@ -195,6 +202,11 @@ <h2>📊 Overall Status</h2>
195202
const response = await fetch(`${API_URL}/FRED-GDP?mode=latest`, {
196203
headers: { 'Authorization': `Bearer ${key}` }
197204
});
205+
if (!response.ok) {
206+
resultDiv.className = 'result error';
207+
resultDiv.textContent = `❌ HTTP ${response.status}: ${response.statusText}`;
208+
return;
209+
}
198210
const data = await response.json();
199211

200212
if (data.error) {
@@ -263,6 +275,13 @@ <h3>Tests Passed: ${passed}/${total} (${percentage}%)</h3>
263275

264276
try {
265277
const response = await fetch('https://www.datasetiq.com/api/public/search?q=GDP');
278+
if (!response.ok) {
279+
resultDiv.className = 'result error';
280+
resultDiv.textContent = `❌ HTTP ${response.status}: ${response.statusText}\nURL: ${response.url}`;
281+
testResults['search'] = false;
282+
updateOverallStatus();
283+
return;
284+
}
266285
const data = await response.json();
267286

268287
testResults['search'] = response.status === 200 && Array.isArray(data);
@@ -289,6 +308,13 @@ <h3>Tests Passed: ${passed}/${total} (${percentage}%)</h3>
289308

290309
try {
291310
const response = await fetch('https://www.datasetiq.com/api/public/search?q=GDP&source=FRED');
311+
if (!response.ok) {
312+
resultDiv.className = 'result error';
313+
resultDiv.textContent = `❌ HTTP ${response.status}: ${response.statusText}`;
314+
testResults['search-source'] = false;
315+
updateOverallStatus();
316+
return;
317+
}
292318
const data = await response.json();
293319

294320
testResults['search-source'] = response.status === 200 && Array.isArray(data);
@@ -315,6 +341,13 @@ <h3>Tests Passed: ${passed}/${total} (${percentage}%)</h3>
315341

316342
try {
317343
const response = await fetch(`https://www.datasetiq.com/api/public/search?source=${source}&limit=50`);
344+
if (!response.ok) {
345+
resultDiv.className = 'result error';
346+
resultDiv.textContent = `❌ HTTP ${response.status}: ${response.statusText}\nURL: ${response.url}`;
347+
testResults[`browse-${source}`] = false;
348+
updateOverallStatus();
349+
return;
350+
}
318351
const data = await response.json();
319352

320353
testResults[`browse-${source}`] = response.status === 200 && Array.isArray(data);

0 commit comments

Comments
 (0)