AI workspace
request.ts
Prompt
Add clear error handling to this request.
Suggested change
TypeScript
-
export async function getData(): Promise<Data> { -
const response = await fetch("/api/data"); -
if (!response.ok) { -
throw new Error("Request failed"); -
} -
return response.json() as Promise<Data>; -
}
Ready for review
request.ts