Skip to content

fix(export): send credentials and surface server error on USFM export#312

Merged
henrique221 merged 2 commits into
mainfrom
fix/195-usfm-export-credentials-error-ux
Jun 23, 2026
Merged

fix(export): send credentials and surface server error on USFM export#312
henrique221 merged 2 commits into
mainfrom
fix/195-usfm-export-credentials-error-ux

Conversation

@henrique221

@henrique221 henrique221 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Part of eten-tech-foundation/fluent-api#195.

Summary

useExportUsfm was the only API call in the app that omitted
credentials: 'include'. It worked only because the export endpoint was
unauthenticated; once fluent-api requires auth
(eten-tech-foundation/fluent-api#189), the request would 401 and the editor
export would break.

  • Add credentials: 'include' so the session cookie is sent.
  • Parse the JSON error body (supports both the { message } envelope and the
    USFM route's { error } shape) and surface it, so ExportProjectDialog shows
    the actual reason (e.g. "Invalid book IDs", "No books available") instead of a
    hardcoded "Export Failed". The dialog already had the inline error UI + logging.

⚠️ Release coupling

This must deploy with or before fluent-api#189's auth change, or the editor
export will 401.

Test plan

  • pnpm typecheck
  • pnpm lint (changed files)
  • pnpm test — 38/38 pass

Summary by CodeRabbit

Bug Fixes

  • Improved error messaging for project export operations. When exports encounter failures, users now receive specific, actionable error details instead of generic failure messages. This provides clearer information to help users understand what went wrong and resolve export issues more effectively.

useExportUsfm omitted credentials: 'include' — the only API call in the app
that did. It worked only because the export endpoint was unauthenticated;
once fluent-api requires auth (eten-tech-foundation/fluent-api#189) the
request would 401 and the editor export would break.

- Add credentials: 'include' so the session cookie is sent.
- Parse the JSON error body (supports both { message } and the USFM route's
  { error } shape) and surface it, so ExportProjectDialog shows the actual
  reason (e.g. 'Invalid book IDs') instead of a hardcoded 'Export Failed'.

Refs eten-tech-foundation/fluent-api#195
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4d695713-c8d5-42a1-bdbc-bb15b352a185

📥 Commits

Reviewing files that changed from the base of the PR and between 29325ef and 249bd71.

📒 Files selected for processing (2)
  • src/features/projects/components/ExportProjectDialog.tsx
  • src/features/projects/hooks/useExportUsfm.ts

📝 Walkthrough

Walkthrough

The USFM export hook gains a parseExportError helper that parses failed HTTP responses as JSON to extract a message or error field, falling back to a default string. The fetch call now includes credentials: 'include'. The export dialog's catch block is updated to display the error's message property when the thrown value is an Error.

Changes

USFM Export Error Handling

Layer / File(s) Summary
Server error parsing and credential forwarding
src/features/projects/hooks/useExportUsfm.ts
Adds DEFAULT_EXPORT_ERROR constant and parseExportError(response) helper that attempts response.json() and returns message or error from the body, falling back to the default. Updates exportUsfmRequest to pass credentials: 'include' and throw new Error(await parseExportError(response)) on non-OK responses.
Export dialog error display
src/features/projects/components/ExportProjectDialog.tsx
Changes the catch block error state assignment to use err.message when the caught value is an Error instance, with a fallback to 'Export Failed'.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding credentials to the fetch call and improving error handling to surface server errors in USFM export.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/195-usfm-export-credentials-error-ux

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: dependency version conflict. Check your lock file or package.json.


Comment @coderabbitai help to get the list of available commands and usage tips.

@henrique221
henrique221 enabled auto-merge (squash) June 23, 2026 17:33
@henrique221
henrique221 merged commit 46c7dc6 into main Jun 23, 2026
2 checks passed
@github-actions
github-actions Bot deleted the fix/195-usfm-export-credentials-error-ux branch June 23, 2026 17:34
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.

2 participants