π Description
Problem
// β No status validation - treats errors as events
const res = await fetch(https://api.github.com/users/${username}/events);
const data = await res.json();
setEvents(data); // Could be error object!
Solution
// β
Validate response before parsing
const res = await fetch(https://api.github.com/users/${username}/events);
if (res.ok) {
const data = await res.json();
setEvents(data);
} else {
setEvents([]);
console.error("Failed to fetch events");
}
What browsers are you seeing the problem on?
No response
π Relevant Screenshots (Links)
No response
π Description
Problem
// β No status validation - treats errors as events
const res = await fetch(
https://api.github.com/users/${username}/events);const data = await res.json();
setEvents(data); // Could be error object!
Solution
// β Validate response before parsing
const res = await fetch(
https://api.github.com/users/${username}/events);if (res.ok) {
const data = await res.json();
setEvents(data);
} else {
setEvents([]);
console.error("Failed to fetch events");
}
What browsers are you seeing the problem on?
No response
π Relevant Screenshots (Links)
No response