Skip to content

fix: frontend API calls lack retry logic — single RPC failure breaks entire page #800

Description

@sanmipaul

Bug

All Soroban RPC calls in the Astera frontend fail immediately on the first error with no retry. Stellar Horizon and Soroban RPC servers occasionally return transient errors (rate limiting, momentary unavailability, network blips). A single transient error currently causes the entire page component to enter an error state that requires a full page reload to recover.

Impact

  • User sees "Error loading data" for a transient 500ms RPC outage
  • No automatic recovery without manual refresh
  • Dashboard unusable during any RPC instability

Fix

Add retry logic to SWR hooks with exponential backoff:

```ts
// frontend/lib/swrConfig.ts
export const swrConfig: SWRConfiguration = {
onErrorRetry: (error, key, config, revalidate, { retryCount }) => {
// Don't retry on 404 (not found — permanent)
if (error.status === 404) return;
// Retry up to 3 times with exponential backoff
if (retryCount >= 3) return;
setTimeout(() => revalidate({ retryCount }), 1000 * Math.pow(2, retryCount));
},
errorRetryCount: 3,
errorRetryInterval: 1000,
};
```

Apply this config globally in `_app.tsx` or `layout.tsx` via `SWRConfig`.

For one-off fetch calls, wrap with a retry utility:

```ts
async function withRetry(fn: () => Promise, retries = 3): Promise {
for (let i = 0; i < retries; i++) {
try { return await fn(); }
catch (e) { if (i === retries - 1) throw e; await sleep(1000 * 2**i); }
}
throw new Error('unreachable');
}
```

Acceptance Criteria

  • SWR hooks retry up to 3 times on transient errors
  • Exponential backoff between retries (1s, 2s, 4s)
  • 404 errors are NOT retried (permanent failure)
  • User sees a subtle "Retrying..." indicator, not a full error state, during retries
  • After 3 failures, error state is shown with a manual "Retry" button
  • Unit test: mock RPC fails twice then succeeds → data loads correctly

References

  • `frontend/lib/` — API/SWR hook configuration
  • SWR documentation: `onErrorRetry`

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workingfrontendNext.js frontend work

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions