Skip to content

Improve API error diagnostics, validation, and retry UX#23

Open
wsxiaolin wants to merge 1 commit intomainfrom
codex/improve-error-logging-and-handling
Open

Improve API error diagnostics, validation, and retry UX#23
wsxiaolin wants to merge 1 commit intomainfrom
codex/improve-error-logging-and-handling

Conversation

@wsxiaolin
Copy link
Copy Markdown
Member

Motivation

  • Make runtime errors easier to inspect in both development and production by ensuring console output preserves full, expandable Error objects and stacks.
  • Avoid losing actionable stack information when persisting logs to local storage.
  • Reduce unexpected cannot read properties of undefined errors caused by malformed or non-JSON API responses by validating and surfacing those failures earlier.
  • Give users a clear, retryable UI when network/HTTP/ business-level failures occur so transient problems can be retried from the same dialog.

Description

  • Changed console output in src/services/errorLogger.ts to always call console.error(...) with the original Error object or full stack so browser consoles retain full expandable stacks.
  • Stopped truncating stacks when saving logs to localStorage and now persist the full stack string for each saved error.
  • Enhanced getData in src/services/api/getData.ts to validate response shape, log malformed responses, and treat JSON parse failures as network errors.
  • Integrated the retryable API error dialog (showAPiError) for HTTP non-2xx responses, malformed/non-object responses, and business-level Status !== 200 responses; these cases now log to the error logger and offer a retry handler that re-invokes the original getData call.

Testing

  • Ran the production build with npm run build, which includes vue-tsc and vite build, and it completed successfully.
  • Verified the app compiles and the changes to src/services/errorLogger.ts and src/services/api/getData.ts are type-checked as part of the build.
  • No additional automated unit tests were present or executed for these changes.

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7a700c062d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

breadcrumbs: [...window.$ErrorLogger.getBreadcrumbs()],
});
showRetryableApiError(`Invalid response from ${npath}`);
return data;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject invalid API response shapes

When response.json() returns a non-object payload, this branch logs and shows a dialog but still resolves the promise with the raw value, which violates getData’s typed Promise<APIResult<...>> contract and pushes the failure into callers that immediately dereference re.Status/re.Data. Before this change, malformed payloads like null would fail inside getData; now they can escape as “successful” results and trigger downstream runtime errors in unrelated components.

Useful? React with 👍 / 👎.

Comment on lines +130 to +132
showRetryableApiError(
`${npath} returned business status ${String(data.Status ?? "unknown")}`,
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Limit retry modal to truly retryable failures

This now opens the global retry dialog for every business-level non-200 response, including expected validation outcomes that the caller already handles (for example /Users/Follow returns 400 for self-follow and the UI shows a specific message). The result is duplicate/conflicting error UX and a misleading “network error” retry prompt for non-retryable user-input errors.

Useful? React with 👍 / 👎.

@wsxiaolin wsxiaolin removed the codex label May 4, 2026
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.

1 participant