Skip to content

Commit c3e50e7

Browse files
authored
fix(google-docs): show error if agents api fails to process [INTEG-3419] (#10451)
1 parent 4fa476d commit c3e50e7

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

apps/google-docs/src/hooks/useGeneratePreview.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const parseAgentResponse = (data: any): AgentResponse => {
5757
} catch {
5858
// We do not throw an error here because we want to continue parsing the other parts
5959
// and other parts may already be valid and correctly parsed
60-
console.warn('[parseAgentResponse] Failed to parse part:', { part, text: part.text });
60+
console.warn('Failed to parse part:', { part, text: part.text });
6161
}
6262
}
6363

@@ -110,14 +110,15 @@ const callGoogleDocsAgent = async (
110110
}
111111

112112
const data = await response.text();
113+
114+
let parsedData: any;
113115
try {
114-
const parsedData = JSON.parse(data);
115-
return parseAgentResponse(parsedData);
116-
} catch (error) {
117-
console.error('[callGoogleDocsAgent] Failed to parse response:', error);
118-
// Graceful fall back state so app doesn't crash but we still know there was an error
119-
return { entries: [], assets: [] };
116+
parsedData = JSON.parse(data);
117+
} catch {
118+
throw new Error('Failed to parse google docs agent response as JSON');
120119
}
120+
121+
return parseAgentResponse(parsedData);
121122
};
122123

123124
interface UseGeneratePreviewResult {
@@ -201,6 +202,10 @@ export const useGeneratePreview = ({
201202
setPreviewEntries(previewEntriesWithTitles);
202203
setAssets(agentAssets);
203204
} catch (err) {
205+
console.error(
206+
'Error generating preview:',
207+
err instanceof Error ? err.message : String(err)
208+
);
204209
setError(err instanceof Error ? err : new Error(String(err)));
205210
} finally {
206211
setIsSubmitting(false);

apps/google-docs/src/locations/Page/components/mainpage/OAuthConnector.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ export const OAuthConnector = ({
5252

5353
for (let attempt = 1; attempt <= maxRetries; attempt++) {
5454
try {
55-
console.log(
56-
`Checking Google OAuth connection status (attempt ${attempt}/${maxRetries})...`
57-
);
58-
5955
const { connected, token } = await callAppActionWithResult<CheckStatusResponse>(
6056
sdk,
6157
'checkGdocOauthTokenStatus',
@@ -64,19 +60,13 @@ export const OAuthConnector = ({
6460

6561
// Assuming the response contains a connected field
6662
const isConnected = connected === true;
67-
console.log(`Google OAuth connection status (attempt ${attempt}):`, isConnected);
6863
onOauthTokenChange(token);
6964

7065
// If we have an expected status and it matches, or if we don't have an expected status, accept the result
7166
if (expectedStatus === undefined || isConnected === expectedStatus) {
7267
onOAuthConnectedChange(isConnected);
73-
console.log(`Status check resolved to expected value: ${isConnected}`);
7468
break;
7569
} else {
76-
console.log(
77-
`Status mismatch. Expected: ${expectedStatus}, Got: ${isConnected}. Retrying...`
78-
);
79-
8070
// If this is the last attempt, accept the current result anyway
8171
if (attempt === maxRetries) {
8272
console.log(`Max retries reached. Accepting current status: ${isConnected}`);
@@ -86,7 +76,6 @@ export const OAuthConnector = ({
8676

8777
// Wait before retrying (exponential backoff: 500ms, 1000ms, 1500ms, etc.)
8878
const waitTime = 500 * attempt;
89-
console.log(`Waiting ${waitTime}ms before retry...`);
9079
await delay(waitTime);
9180
}
9281
} catch (error) {
@@ -101,13 +90,11 @@ export const OAuthConnector = ({
10190

10291
// Wait before retrying on error
10392
const waitTime = 500 * attempt;
104-
console.log(`Waiting ${waitTime}ms before retry after error...`);
10593
await delay(waitTime);
10694
}
10795
}
10896

10997
setLoadingState(OAuthLoadingState.IDLE);
110-
console.log(`Status check polling completed. Final status: ${isOAuthConnected}`);
11198
};
11299

113100
const messageHandler = async (event: MessageEvent) => {

0 commit comments

Comments
 (0)