WIP Replace raw fetch() calls with typed openapi-fetch client#1188
WIP Replace raw fetch() calls with typed openapi-fetch client#1188
Conversation
Convert three remaining fetch() calls in connect_providers.svelte and connect_kiln_copilot_steps.svelte to use the typed openapi-fetch client, gaining compile-time path checking and consistent error handling. Remove now-unused base_url imports. Mark Phase 1 of typed-client-migration as complete. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
WalkthroughThis PR migrates raw Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request migrates raw fetch calls in the Svelte frontend to a typed openapi-fetch client, specifically for provider connection and settings endpoints. This change improves type safety and centralizes API configuration. The PR also includes detailed documentation covering the architecture, functional specifications, and implementation plan for this migration. My feedback focuses on improving the robustness of the new implementation: first, by ensuring that the detail field in error responses is properly validated as a string before UI display to avoid showing [object Object]; and second, by adding a guard clause to verify that the data object is defined before accessing its properties to prevent runtime errors.
| (err.message as string) || | ||
| (err.detail as string) || |
There was a problem hiding this comment.
The detail field in FastAPI error responses (such as 422 Validation Errors) is frequently an array of objects rather than a string. Casting it directly to string and assigning it to apiKeyMessage may result in [object Object] being displayed in the UI. It is safer to verify that detail is a string before assignment.
(err.message as string) ||
(typeof err.detail === "string" ? err.detail : null) ||
| if (error) { | ||
| throw error | ||
| } | ||
| if (data["open_ai_api_key"]) { |
There was a problem hiding this comment.
The data object returned by the typed client is optional and could be undefined if the response body is empty. Accessing data["open_ai_api_key"] without a guard clause may lead to a runtime error. Adding a check for data after the error handling ensures the function exits gracefully if no data is returned.
if (!data) return
if (data["open_ai_api_key"]) {
📊 Coverage ReportOverall Coverage: 91% Diff: origin/scosman/improve-api-docs...HEADNo lines with coverage information in this diff.
|
Convert three remaining fetch() calls in connect_providers.svelte and connect_kiln_copilot_steps.svelte to use the typed openapi-fetch client, gaining compile-time path checking and consistent error handling. Remove now-unused base_url imports. Mark Phase 1 of typed-client-migration as complete.
retarget to main once improve-api-docs is merged
Summary by CodeRabbit
Refactor
Chores