fix(HAI-036): add retry logic to fetchTaskDetail
- Convert fetchTaskDetail to async with explicit fetch call - Add single retry attempt on failure (2 max attempts) - Parse and throw server error message on final failure
This commit is contained in:
@@ -14,8 +14,20 @@ export function fetchTasks(): Promise<Task[]> {
|
|||||||
return api<Task[]>("/tasks");
|
return api<Task[]>("/tasks");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchTaskDetail(id: string): Promise<TaskDetail> {
|
export async function fetchTaskDetail(id: string): Promise<TaskDetail> {
|
||||||
return api<TaskDetail>(`/tasks/${id}`);
|
const maxAttempts = 2; // 1 initial + 1 retry
|
||||||
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
||||||
|
const res = await fetch(`/api/tasks/${id}`, {
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
const data = await res.json();
|
||||||
|
if (res.ok) return data as TaskDetail;
|
||||||
|
if (attempt === maxAttempts) {
|
||||||
|
throw new Error((data as { error?: string }).error || "Request failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// unreachable
|
||||||
|
throw new Error("Request failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createTask(input: TaskCreateInput): Promise<Task> {
|
export function createTask(input: TaskCreateInput): Promise<Task> {
|
||||||
|
|||||||
Reference in New Issue
Block a user