Skip to content

fix(generate): add robust API failure handling and retry mechanisms#172

Open
mithilP007 wants to merge 3 commits into
SATYAM-PRATIBHAN:mainfrom
mithilP007:fix/api-failure-handling
Open

fix(generate): add robust API failure handling and retry mechanisms#172
mithilP007 wants to merge 3 commits into
SATYAM-PRATIBHAN:mainfrom
mithilP007:fix/api-failure-handling

Conversation

@mithilP007
Copy link
Copy Markdown

Resolves missing API failure handling bugs across generate hooks and pages.

Copilot AI review requested due to automatic review settings May 18, 2026 07:16
@netlify
Copy link
Copy Markdown

netlify Bot commented May 18, 2026

👷 Deploy request for arcmind-ai pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit ba938c2

@mithilP007
Copy link
Copy Markdown
Author

Solved under Gssoc 2026

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 this catch, err.message will usually just be "Request failed with status code …"; prefer axios.isAxiosError(err) and read err.response?.data?.error / details to populate errorMessage and setError with 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 };
}
@SATYAM-PRATIBHAN
Copy link
Copy Markdown
Owner

@mithilP007 merge conflicts!!

@mithilP007 mithilP007 force-pushed the fix/api-failure-handling branch from 65a0c13 to ba938c2 Compare May 19, 2026 15:45
@SATYAM-PRATIBHAN
Copy link
Copy Markdown
Owner

@mithilP007 conflicts to solve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants