refactor(cli): centralize HTTP status error mapping#285
refactor(cli): centralize HTTP status error mapping#285
Conversation
Users have seen an elevated number of:\n clawdhub search image\n ✖ Non-error was thrown: "Timeout". You should only throw errors.\n\nInvestigation shows we were aborting with a string instead of an Error. Switching to controller.abort(new Error('Timeout')) makes retries/formatting treat it as a real error and clears the message.\n\nExample after change:\n clawdhub search image\n table-image v1.0.0 Table Image (0.332)\n nano-banana-pro v1.0.1 Nano Banana Pro (0.319)\n vap-media v1.0.1 AI media generation API - Flux2pro, Veo3.1, Suno Ai (0.281)\n clawdbot-meshyai-skill v0.1.0 Meshy AI (0.276)\n venice-ai-media v1.0.0 Venice AI Media (0.274)\n daily-recap v1.0.2 Daily Recap (0.260)\n openai-image-gen v1.0.1 Openai Image Gen (0.260)\n bible-votd v1.0.1 Bible Verse of the Day (0.248)\n orf v1.0.1 ORF (0.224)\n smalltalk v1.0.1 Smalltalk (0.161)
Addresses Vercel review comment: clearTimeout was not called on error paths when fetch throws an exception.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview Replaces per-call timeout wiring in Written by Cursor Bugbot for commit f697310. This will update automatically on new commits. Configure here. |
|
Superseded by #286 (clean branch, same changes). |
Additional Comments (1)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/clawdhub/src/http.ts
Line: 298:303
Comment:
`fetchTextViaCurl` still has duplicated error handling logic instead of using the centralized `throwHttpStatusError` helper
```suggestion
if (status < 200 || status >= 300) {
throwHttpStatusError(status, body)
}
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| if (status === 429 || status >= 500) { | ||
| throw new Error(body || `HTTP ${status}`) | ||
| } | ||
| throw new AbortError(body || `HTTP ${status}`) |
There was a problem hiding this comment.
fetchTextViaCurl not refactored to use centralized helper
Low Severity
fetchTextViaCurl still contains the old inline error-handling pattern (if (status === 429 || status >= 500) … throw new AbortError(…)) instead of calling the new throwHttpStatusError helper. Every other curl function (fetchJsonViaCurl, fetchJsonFormViaCurl, fetchBinaryViaCurl) was updated to use the centralized helper, making this the only remaining duplication — which defeats the stated purpose of the refactor and risks divergent bug fixes in the future.


Summary
Testing
Greptile Overview
Greptile Summary
Refactored HTTP request error handling by centralizing status-to-error mapping logic into a single
throwHttpStatusErrorhelper function and extractingfetchWithTimeoutandreadResponseTextSafehelpers to eliminate duplication acrossapiRequest,apiRequestForm,fetchText, anddownloadZip.Key changes:
fetchWithTimeouthelper that properly wraps abort signals and ensuresclearTimeoutis called in a finally block'Timeout'toError('Timeout')for consistent error handlingreadResponseTextSafeto safely extract response text with fallbackthrowHttpStatusError(429 and 5xx throw retryableError, others throwAbortError)throwHttpStatusError, exceptfetchTextViaCurlwhich still contains duplicated logicclearTimeoutassertions forapiRequestandfetchTextpathsOne function (
fetchTextViaCurlat lines 298-303) was not refactored and still contains the old duplicated error handling pattern.Confidence Score: 4/5
fetchTextViaCurlfetchTextViaCurl) was not updated to use the new centralized helper, leaving inconsistent error handling that defeats the purpose of the refactor. This is a straightforward fix but important for maintaining code consistency.packages/clawdhub/src/http.tsline 298-303 wherefetchTextViaCurlneeds to usethrowHttpStatusErrorLast reviewed commit: f697310