fix(generate): add robust API failure handling and retry mechanisms#172
Open
mithilP007 wants to merge 3 commits into
Open
fix(generate): add robust API failure handling and retry mechanisms#172mithilP007 wants to merge 3 commits into
mithilP007 wants to merge 3 commits into
Conversation
👷 Deploy request for arcmind-ai pending review.Visit the deploys page to approve it
|
Author
|
Solved under Gssoc 2026 |
There was a problem hiding this comment.
Pull request overview
This PR aims to improve resilience of the protected “generate” flows by surfacing API-level failures more consistently and adding user-facing retry options on pages that fetch/generate derived artifacts.
Changes:
- Added
success-flag validation for tasks and generation-by-id hooks (throws when API indicates failure). - Updated the system generation hook/page flow to return structured
{ success, output?, error? }results and improved client-side error display/parsing feedback. - Added retry UX for task breakdown and frontend structure pages.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| app/(protected)/generate/hooks/useGetTasks.ts | Adds API success validation when fetching tasks. |
| app/(protected)/generate/hooks/useGetGenerationById.ts | Extends response typing and throws on success: false. |
| app/(protected)/generate/hooks/useGenerateSystem.ts | Changes generate return shape to include structured error results. |
| app/(protected)/generate/components/GeneratePage.tsx | Clears errors before generate, tightens success/output checks, improves parse-failure messaging. |
| app/(protected)/generate/[id]/tasks/page.tsx | Adds retry button and refetch tracking keyed by retry count. |
| app/(protected)/generate/[id]/frontendStructure/page.tsx | Adds retry button wired to generateFrontendStructure(). |
Comments suppressed due to low confidence (1)
app/(protected)/generate/hooks/useGenerateSystem.ts:51
- On failures, the generate API returns a JSON body like
{ error: string, details?: string }with a non-2xx status (e.g. 422/429/503). In thiscatch,err.messagewill usually just be "Request failed with status code …"; preferaxios.isAxiosError(err)and readerr.response?.data?.error/detailsto populateerrorMessageandsetErrorwith something actionable.
} catch (err) {
const errorMessage =
err instanceof Error ? err.message : "An error occurred";
setError(errorMessage);
return { success: false, error: errorMessage };
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
54
to
+57
| const data: TasksResponse = response.data; | ||
| if (!data.success) { | ||
| throw new Error(data.message || "Failed to fetch tasks"); | ||
| } |
Comment on lines
+54
to
+58
|
|
||
| if (!data.success) { | ||
| throw new Error(data.message || data.error || "Failed to fetch generation"); | ||
| } | ||
|
|
Comment on lines
+55
to
+57
| if (!data.success) { | ||
| throw new Error(data.message || data.error || "Failed to fetch generation"); | ||
| } |
Comment on lines
72
to
77
| const handleGenerate = async () => { | ||
| setError(null); | ||
| const result = await generate(userInput); | ||
| if (result && result.success) { | ||
| if (result && result.success && result.output) { | ||
| try { | ||
| let cleanedOutput = result.output; |
Comment on lines
+48
to
51
| lastFetchedId.current = id; | ||
| lastRetryCount.current = retryCount; | ||
| const result = await getTasks(id); | ||
| if (result && result.success) { |
Comment on lines
16
to
24
| const generate = async ( | ||
| userInput: string, | ||
| ): Promise<GenerateResponse | null> => { | ||
| ): Promise<{ success: boolean; output?: string; error?: string } | null> => { | ||
| // @ts-expect-error accessToken is added to session in NextAuth callbacks | ||
| if (!session?.user?.accessToken) { | ||
| setError("No access token available. Please log in."); | ||
| return null; | ||
| const msg = "No access token available. Please log in."; | ||
| setError(msg); | ||
| return { success: false, error: msg }; | ||
| } |
Owner
|
@mithilP007 merge conflicts!! |
65a0c13 to
ba938c2
Compare
Owner
|
@mithilP007 conflicts to solve |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves missing API failure handling bugs across generate hooks and pages.