Fix common API error with promise reject#1614
Conversation
Signed-off-by: prxt6529 <prxt@6529.io>
WalkthroughError handling in the API layer was changed to return Promise rejections with error message strings instead of throwing Error objects; tests were updated to assert rejected values directly. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as API caller
participant Handler as handleApiError
participant Promise as Promise chain
rect rgb(250,250,255)
Note over Handler: Previous flow (throw)
Client->>Handler: API error detected
Handler->>Handler: throw new Error(msg)
Handler-->>Promise: exception thrown (Error object)
end
rect rgb(240,255,240)
Note over Handler: New flow (reject)
Client->>Handler: API error detected
Handler->>Handler: return Promise.reject(msg)
Handler-->>Promise: rejected with string
Promise-->>Client: rejection handled by callers/tests
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🪛 GitHub Check: SonarCloud Code Analysisservices/api/common-api.ts[failure] 55-55: Prefer [warning] 55-55: Expected the Promise rejection reason to be an Error. ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
__tests__/services/common-api.postNoBody.test.ts(1 hunks)__tests__/services/common-api.test.ts(2 hunks)services/api/common-api.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
__tests__/services/common-api.test.ts (2)
services/api/common-api.ts (2)
commonApiFetch(86-111)commonApiPost(232-251)__mocks__/@/services/api/common-api.ts (2)
commonApiFetch(11-11)commonApiPost(13-13)
🪛 GitHub Check: SonarCloud Code Analysis
services/api/common-api.ts
[warning] 56-56: Expected the Promise rejection reason to be an Error.
[warning] 55-55: Replace this trivial promise with "Promise.reject".
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
__tests__/services/common-api.test.ts (2)
53-53: Test assertion correctly updated.The test now correctly expects the promise to reject with the string value
"err"rather than throwing an Error object, aligning with the implementation change inhandleApiError.
106-108: Test assertion correctly updated.The test now correctly expects the promise to reject with the string value
"err"rather than throwing an Error object, consistent with the new error handling behavior.__tests__/services/common-api.postNoBody.test.ts (1)
41-41: Test assertion correctly updated.The test now correctly expects the promise to reject with the string value
"err", matching the updated error handling semantics inhandleApiError.
|

Summary by CodeRabbit
Tests
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.