[PR #286] [MERGED] refactor(cli): centralize HTTP status error mapping #311

Closed
opened 2026-02-15 17:16:48 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/openclaw/clawhub/pull/286
Author: @steipete
Created: 2/13/2026
Status: Merged
Merged: 2/13/2026
Merged by: @steipete

Base: mainHead: fix/http-timeout-followups-clean


📝 Commits (1)

  • b43bcd8 refactor(cli): centralize HTTP status errors and timeout tests

📊 Changes

2 files changed (+73 additions, -61 deletions)

View changed files

📝 packages/clawdhub/src/http.test.ts (+54 -26)
📝 packages/clawdhub/src/http.ts (+19 -35)

📄 Description

Summary

  • centralize HTTP status-to-error mapping in one helper
  • reuse safe response text helper across request paths
  • add timeout coverage for apiRequest path
  • assert clearTimeout calls in timeout regression tests

Testing

  • bun run lint
  • bun run test packages/clawdhub/src/http.test.ts

Greptile Overview

Greptile Summary

This PR extracts duplicated HTTP status-to-error mapping logic into a centralized throwHttpStatusError helper and a readResponseTextSafe utility in packages/clawdhub/src/http.ts. It also adds timeout coverage for the apiRequest path and strengthens existing timeout tests with clearTimeout assertions.

  • Introduced throwHttpStatusError(status, text): never to replace 6 inline copies of the retry-vs-abort error logic
  • Introduced readResponseTextSafe(response) to replace repeated .text().catch(() => '') calls
  • Added new apiRequest timeout test and shared test helpers (mockImmediateTimeouts, createAbortingFetchMock)
  • Issue: fetchTextViaCurl (line 298-303) was not converted to use the new helper, leaving one remaining instance of the old inline pattern

Confidence Score: 4/5

  • This PR is safe to merge — the refactoring is behavior-preserving and well-tested, with one minor missed spot that doesn't change existing behavior.
  • The refactoring correctly centralizes error handling across all but one call site. The missed fetchTextViaCurl is not a regression (behavior is unchanged from before), but it contradicts the PR's stated goal of full centralization. Tests are thorough and cover the new code paths.
  • packages/clawdhub/src/http.ts — fetchTextViaCurl still uses inline error handling instead of throwHttpStatusError

Last reviewed commit: b43bcd8

Context used:

  • Context from dashboard - AGENTS.md (source)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/openclaw/clawhub/pull/286 **Author:** [@steipete](https://github.com/steipete) **Created:** 2/13/2026 **Status:** ✅ Merged **Merged:** 2/13/2026 **Merged by:** [@steipete](https://github.com/steipete) **Base:** `main` ← **Head:** `fix/http-timeout-followups-clean` --- ### 📝 Commits (1) - [`b43bcd8`](https://github.com/openclaw/clawhub/commit/b43bcd87503dcb78cf113909626a97c12f9a13c2) refactor(cli): centralize HTTP status errors and timeout tests ### 📊 Changes **2 files changed** (+73 additions, -61 deletions) <details> <summary>View changed files</summary> 📝 `packages/clawdhub/src/http.test.ts` (+54 -26) 📝 `packages/clawdhub/src/http.ts` (+19 -35) </details> ### 📄 Description ## Summary - centralize HTTP status-to-error mapping in one helper - reuse safe response text helper across request paths - add timeout coverage for apiRequest path - assert clearTimeout calls in timeout regression tests ## Testing - bun run lint - bun run test packages/clawdhub/src/http.test.ts <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR extracts duplicated HTTP status-to-error mapping logic into a centralized `throwHttpStatusError` helper and a `readResponseTextSafe` utility in `packages/clawdhub/src/http.ts`. It also adds timeout coverage for the `apiRequest` path and strengthens existing timeout tests with `clearTimeout` assertions. - Introduced `throwHttpStatusError(status, text): never` to replace 6 inline copies of the retry-vs-abort error logic - Introduced `readResponseTextSafe(response)` to replace repeated `.text().catch(() => '')` calls - Added new `apiRequest` timeout test and shared test helpers (`mockImmediateTimeouts`, `createAbortingFetchMock`) - **Issue**: `fetchTextViaCurl` (line 298-303) was not converted to use the new helper, leaving one remaining instance of the old inline pattern <h3>Confidence Score: 4/5</h3> - This PR is safe to merge — the refactoring is behavior-preserving and well-tested, with one minor missed spot that doesn't change existing behavior. - The refactoring correctly centralizes error handling across all but one call site. The missed fetchTextViaCurl is not a regression (behavior is unchanged from before), but it contradicts the PR's stated goal of full centralization. Tests are thorough and cover the new code paths. - packages/clawdhub/src/http.ts — fetchTextViaCurl still uses inline error handling instead of throwHttpStatusError <sub>Last reviewed commit: b43bcd8</sub> <!-- greptile_other_comments_section --> **Context used:** - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=a1d58d20-b4dd-4cbb-973a-9fd7824e1921)) <!-- /greptile_comment --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 17:16:48 -05:00
yindo closed this issue 2026-02-15 17:16:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: openclaw/clawhub#311