Skip to content

feat(hooks): add stable useApi refetch API and retry integration - #461

Merged
mikewheeleer merged 3 commits into
Agentpay-Org:mainfrom
mysterio123865:main
Jul 28, 2026
Merged

feat(hooks): add stable useApi refetch API and retry integration#461
mikewheeleer merged 3 commits into
Agentpay-Org:mainfrom
mysterio123865:main

Conversation

@mysterio123865

Copy link
Copy Markdown
Contributor

Summary

This PR enhances the useApi hook by introducing a stable refetch() API that can be invoked regardless of the current request state. The update improves error recovery and manual refresh behavior while preserving backward compatibility with the existing retry mechanism.

What Was Implemented

🔄 Stable refetch() API

Updated useApi to expose a stable refetch() function throughout the request lifecycle.

The new implementation:

  • Returns refetch() regardless of loading, success, or error state.
  • Aborts any in-flight request before starting a new fetch.
  • Re-executes the original request using the existing hook configuration.
  • Preserves the existing retry API as an alias for backward compatibility.

🖥️ Agent Detail Error Recovery

Improved the agent detail page by replacing the previous static error state with a functional retry experience.

Changes include:

  • Replaced the dead-end error message with ErrorMessage.
  • Connected the retry action via onRetry={usageState.refetch}.
  • Allows users to retry failed requests directly from the UI.

📚 Documentation

Updated docs/hooks.md to document:

  • The new refetch() contract.
  • Expected behavior during active requests.
  • Backward compatibility with retry.

Testing

Added comprehensive test coverage for the new behavior, including:

  • Stable refetch() availability across all request states.
  • Aborting in-flight requests before refetching.
  • Successful recovery after request failures.
  • Safe no-op behavior when no request path is configured.
  • Automatic refetch when connectivity is restored.

Validation

  • ✅ Changed-file lint passed.
  • useApi and agent page test suites: 34 tests passed.
  • useApi.ts achieved approximately 100% statement/function/line coverage and ~94% branch coverage.
  • npm run build passed.

Notes

Repository-wide validation still includes pre-existing unrelated issues:

  • Existing api-keys test failures.
  • Existing lint failures in services/[serviceId]/edit/page.tsx.

These issues are unrelated to the changes introduced in this PR.

Closes #300

@mikewheeleer

Copy link
Copy Markdown
Contributor

looks good @mysterio123865 — well scoped and easy to review. merging 👍

@mikewheeleer
mikewheeleer merged commit 772266c into Agentpay-Org:main Jul 28, 2026
0 of 2 checks passed
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.

Add a refetch function to the useApi hook return value

2 participants