mediumHallucinated APIsFetch API
The invented flag
A developer asked an AI assistant to add a request timeout to a fetch call that hits a slow internal API. The suggested option compiles fine and never errors, but the request still hangs well past the intended limit.
fetchReport.js
async function fetchReport(reportId) {
const response = await fetch(`/api/reports/${reportId}`, {
timeout: 5000,
});
if (!response.ok) throw new Error('Failed to load report');
return response.json();
}Why does this fetch call still hang past 5 seconds?
The Fetch API has no timeout option — passing it is silently ignored, so the request runs until the browser's own default timeout.
response.ok is undefined until the promise fully settles.
reportId is not URL-encoded before being inserted into the path.
fetch requires an explicit method: 'GET' for a timeout to take effect.