Skip to content

Commit d17b08d

Browse files
authored
Merge pull request #199 from Mkalbani/feat/network-timeout-handling-127
Feat/network timeout handling 127
2 parents f46f792 + ad7b085 commit d17b08d

File tree

4 files changed

+418
-120
lines changed

4 files changed

+418
-120
lines changed

docs/NETWORK_TIMEOUT_HANDLING.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Network Timeout Handling
2+
3+
## Overview
4+
5+
BridgeWise enforces hard request time limits to prevent hanging API calls and keeps reliability high by reusing existing retry/backoff behavior.
6+
7+
## What is implemented
8+
9+
- **Per-request timeout enforcement** for network calls.
10+
- **Timeout-aware retries** using existing retry logic (exponential backoff).
11+
- **Configurable timeout values** at both client and request levels.
12+
13+
## Configuration
14+
15+
### Global timeout (client)
16+
17+
In `RateLimitedApiClient`:
18+
19+
- `timeout` (ms): default per-request timeout.
20+
21+
Example:
22+
23+
```js
24+
const client = new RateLimitedApiClient({
25+
timeout: 8000,
26+
maxRetries: 3,
27+
baseDelay: 800,
28+
});
29+
```
30+
31+
### Request-level timeout override
32+
33+
You can override timeout for a specific request:
34+
35+
```js
36+
await client.get(
37+
'/api/quote',
38+
{},
39+
{
40+
group: 'quotes',
41+
timeout: 3000,
42+
},
43+
);
44+
```
45+
46+
## Retry integration
47+
48+
Timeouts are treated as retryable failures and follow the same retry policy:
49+
50+
- Retry attempts: `maxRetries`
51+
- Delay strategy: exponential backoff (`baseDelay`, capped by `maxDelay`)
52+
- Metrics: `retriedRequests` increments on timeout retries
53+
54+
## Error behavior
55+
56+
When a timeout occurs, the client throws an error with:
57+
58+
- `name: "TimeoutError"`
59+
- `code: "REQUEST_TIMEOUT"`
60+
- `timeoutMs: <configured timeout>`
61+
62+
## Testing guidance (slow API simulation)
63+
64+
To simulate an unresponsive API in tests:
65+
66+
```js
67+
globalThis.fetch = vi.fn().mockImplementation(() => new Promise(() => {}));
68+
```
69+
70+
Expected behavior:
71+
72+
1. Request times out at configured timeout.
73+
2. Retry triggers (if retries remain).
74+
3. Final error is surfaced when retries are exhausted.
75+
76+
## Affected files
77+
78+
- `packages/adapters/stellar/src/rateLimitedApi.js`
79+
- `packages/adapters/stellar/src/rateLimitedApi.test.js`

docs/README.md

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ Welcome to the BridgeWise API documentation! This comprehensive guide covers eve
55
## 📚 Documentation Files
66

77
### Getting Started
8+
89
- **[QUICK_REFERENCE.md](./QUICK_REFERENCE.md)** ⭐ START HERE
910
- Fastest way to get up and running
1011
- Common commands and examples
1112
- Quick troubleshooting
1213
- ~200 lines
1314

1415
### Comprehensive Guides
16+
1517
- **[API_DOCUMENTATION.md](./API_DOCUMENTATION.md)** - MAIN GUIDE
1618
- Complete API overview
1719
- All 11 endpoints documented
@@ -30,6 +32,7 @@ Welcome to the BridgeWise API documentation! This comprehensive guide covers eve
3032
- ~500 lines
3133

3234
### Reference Materials
35+
3336
- **[API_ERRORS.md](./API_ERRORS.md)** - ERROR REFERENCE
3437
- All error codes documented
3538
- HTTP status codes
@@ -46,27 +49,37 @@ Welcome to the BridgeWise API documentation! This comprehensive guide covers eve
4649
- Quality metrics
4750
- Next steps
4851

52+
- **[NETWORK_TIMEOUT_HANDLING.md](./NETWORK_TIMEOUT_HANDLING.md)** - RELIABILITY
53+
- Timeout limits for slow/unresponsive APIs
54+
- Retry behavior on timeout failures
55+
- Simulation/testing guidance
56+
4957
---
5058

5159
## 🚀 Quick Start
5260

5361
### 1. Install Dependencies
62+
5463
```bash
5564
npm install
5665
```
5766

5867
### 2. Start Development Server
68+
5969
```bash
6070
npm run start:dev
6171
```
6272

6373
### 3. Access Swagger UI
74+
6475
Open your browser to:
76+
6577
```
6678
http://localhost:3000/api/docs
6779
```
6880

6981
### 4. Make Your First Request
82+
7083
```bash
7184
# Create a transaction
7285
curl -X POST http://localhost:3000/transactions \
@@ -88,18 +101,21 @@ curl -X POST http://localhost:3000/transactions \
88101
## 📖 Learning Path
89102

90103
### For API Users
104+
91105
1. Read [QUICK_REFERENCE.md](./QUICK_REFERENCE.md) (5 min)
92106
2. Try endpoints in Swagger UI at `/api/docs` (10 min)
93107
3. Review relevant sections in [API_DOCUMENTATION.md](./API_DOCUMENTATION.md) (20 min)
94108
4. Check [API_ERRORS.md](./API_ERRORS.md) for error handling (10 min)
95109

96110
### For Developers
111+
97112
1. Review [IMPLEMENTATION_SUMMARY.md](./IMPLEMENTATION_SUMMARY.md) (10 min)
98113
2. Check [OPENAPI_SPECIFICATION.md](./OPENAPI_SPECIFICATION.md) (15 min)
99114
3. Examine controller decorators in source code (20 min)
100115
4. Review DTOs with Swagger annotations (10 min)
101116

102117
### For DevOps/Integrations
118+
103119
1. Review [API_DOCUMENTATION.md](./API_DOCUMENTATION.md) architecture section
104120
2. Check endpoints and rate limiting in [QUICK_REFERENCE.md](./QUICK_REFERENCE.md)
105121
3. Review CORS and security in [OPENAPI_SPECIFICATION.md](./OPENAPI_SPECIFICATION.md)
@@ -110,24 +126,28 @@ curl -X POST http://localhost:3000/transactions \
110126
## 🔑 Key Features
111127

112128
**Complete OpenAPI/Swagger Documentation**
129+
113130
- All 11 endpoints fully documented
114131
- Interactive Swagger UI for testing
115132
- Request/response examples for every endpoint
116133
- Real-world use cases
117134

118135
**Comprehensive Error Documentation**
136+
119137
- 20+ error codes documented
120138
- HTTP status code mappings
121139
- Example error responses
122140
- Resolution guidance for each error
123141

124142
**Adapter-Specific Annotations**
143+
125144
- Stellar-specific fields clearly marked
126145
- LayerZero omnichain details
127146
- Hop Protocol bridge parameters
128147
- Example data for each blockchain
129148

130149
**Example Responses**
150+
131151
- Multiple examples for different scenarios
132152
- Success and error cases
133153
- Real network data examples
@@ -138,15 +158,18 @@ curl -X POST http://localhost:3000/transactions \
138158
## 🌐 API Overview
139159

140160
### Base URLs
161+
141162
- **Development**: `http://localhost:3000`
142163
- **Production**: `https://api.bridgewise.example.com`
143164

144165
### Supported Networks
166+
145167
- **Stellar** - Direct blockchain payments
146168
- **LayerZero** - Omnichain bridging
147169
- **Hop Protocol** - Multi-chain liquidity bridges
148170

149171
### Core Operations
172+
150173
- **Transactions** - Create, manage, track
151174
- **Fee Estimation** - Network fees across all chains
152175
- **Real-time Updates** - SSE or polling
@@ -155,38 +178,44 @@ curl -X POST http://localhost:3000/transactions \
155178

156179
## 📊 Documentation Statistics
157180

158-
| Category | Count | Lines |
159-
|----------|-------|-------|
160-
| Endpoints | 11 | ~300 |
161-
| Error Codes | 20+ | ~400 |
162-
| Examples | 20+ | ~200 |
163-
| Adapters | 3 | ~100 |
164-
| **Total** | **~** | **~2000** |
181+
| Category | Count | Lines |
182+
| ----------- | ----- | --------- |
183+
| Endpoints | 11 | ~300 |
184+
| Error Codes | 20+ | ~400 |
185+
| Examples | 20+ | ~200 |
186+
| Adapters | 3 | ~100 |
187+
| **Total** | **~** | **~2000** |
165188

166189
---
167190

168191
## 🎯 Common Tasks
169192

170193
### Access Interactive Swagger UI
194+
171195
```
172196
http://localhost:3000/api/docs
173197
```
174198

175199
### Get All Fee Estimates
200+
176201
```bash
177202
curl http://localhost:3000/api/v1/fees
178203
```
179204

180205
### Create a Transaction
206+
181207
See [QUICK_REFERENCE.md](./QUICK_REFERENCE.md) or [API_DOCUMENTATION.md](./API_DOCUMENTATION.md)
182208

183209
### Monitor Transaction with SSE
210+
184211
See Transaction Monitoring section in [API_DOCUMENTATION.md](./API_DOCUMENTATION.md)
185212

186213
### Handle Errors
214+
187215
See [API_ERRORS.md](./API_ERRORS.md) for error codes and solutions
188216

189217
### Check Service Health
218+
190219
```bash
191220
curl http://localhost:3000/api/v1/fees/health
192221
```
@@ -196,13 +225,15 @@ curl http://localhost:3000/api/v1/fees/health
196225
## 🔗 Related Files
197226

198227
### Source Code
228+
199229
- `src/app.controller.ts` - Health check endpoint
200230
- `src/transactions/transactions.controller.ts` - Transaction endpoints (6 endpoints)
201231
- `src/gas-estimation/fee-estimation.controller.ts` - Fee endpoints (3 endpoints)
202232
- `src/transactions/dto/create-transaction.dto.ts` - Transaction creation schema
203233
- `src/transactions/dto/update-transaction.dto.ts` - Transaction update schema
204234

205235
### Configuration
236+
206237
- `src/main.ts` - Swagger/OpenAPI setup
207238
- `package.json` - Dependencies (@nestjs/swagger, swagger-ui-express)
208239

@@ -211,43 +242,54 @@ curl http://localhost:3000/api/v1/fees/health
211242
## ❓ FAQ
212243

213244
### Where do I start?
245+
214246
→ Begin with [QUICK_REFERENCE.md](./QUICK_REFERENCE.md) for a 5-minute overview.
215247

216248
### How do I test the API?
249+
217250
→ Use the interactive Swagger UI at `/api/docs` or use curl commands in [QUICK_REFERENCE.md](./QUICK_REFERENCE.md).
218251

219252
### What are the supported networks?
253+
220254
→ Stellar, LayerZero, and Hop Protocol. See [API_DOCUMENTATION.md](./API_DOCUMENTATION.md) for details.
221255

222256
### How do I handle errors?
257+
223258
→ See [API_ERRORS.md](./API_ERRORS.md) for all error codes and resolution steps.
224259

225260
### Where is the OpenAPI spec?
261+
226262
→ Automatically served at `http://localhost:3000/api/docs` or see [OPENAPI_SPECIFICATION.md](./OPENAPI_SPECIFICATION.md).
227263

228264
### How do I monitor transactions in real-time?
265+
229266
→ Use Server-Sent Events (SSE) at `/transactions/{id}/events` or polling at `/transactions/{id}/poll`.
230267

231268
### What are the rate limits?
269+
232270
→ 10 requests per 60 seconds per IP. See [QUICK_REFERENCE.md](./QUICK_REFERENCE.md) for details.
233271

234272
### Is authentication required?
273+
235274
→ Currently no. Authentication may be added in future versions (see IMPLEMENTATION_SUMMARY.md).
236275

237276
---
238277

239278
## 📞 Support
240279

241280
### Documentation
281+
242282
- **Main Guide**: [API_DOCUMENTATION.md](./API_DOCUMENTATION.md)
243283
- **Quick Help**: [QUICK_REFERENCE.md](./QUICK_REFERENCE.md)
244284
- **Errors**: [API_ERRORS.md](./API_ERRORS.md)
245285

246286
### Interactive Tools
287+
247288
- **Swagger UI**: http://localhost:3000/api/docs (after starting server)
248289
- **OpenAPI JSON**: http://localhost:3000/api-json
249290

250291
### Contact
292+
251293
- **Email**: [email protected]
252294
- **Docs Site**: https://docs.bridgewise.example.com
253295
- **Status**: https://status.bridgewise.example.com
@@ -272,6 +314,7 @@ curl http://localhost:3000/api/v1/fees/health
272314
## 🎉 What's New (v1.0.0)
273315

274316
**Initial Release Features**
317+
275318
- Complete OpenAPI 3.0.0 specification
276319
- 11 fully documented endpoints
277320
- Server-Sent Events (SSE) support
@@ -285,14 +328,14 @@ curl http://localhost:3000/api/v1/fees/health
285328

286329
## 📝 Document Versions
287330

288-
| Document | Version | Updated |
289-
|----------|---------|---------|
290-
| API_DOCUMENTATION.md | 1.0.0 | 2026-01-29 |
291-
| QUICK_REFERENCE.md | 1.0.0 | 2026-01-29 |
292-
| API_ERRORS.md | 1.0.0 | 2026-01-29 |
293-
| OPENAPI_SPECIFICATION.md | 1.0.0 | 2026-01-29 |
294-
| IMPLEMENTATION_SUMMARY.md | 1.0.0 | 2026-01-29 |
295-
| README.md (this file) | 1.0.0 | 2026-01-29 |
331+
| Document | Version | Updated |
332+
| ------------------------- | ------- | ---------- |
333+
| API_DOCUMENTATION.md | 1.0.0 | 2026-01-29 |
334+
| QUICK_REFERENCE.md | 1.0.0 | 2026-01-29 |
335+
| API_ERRORS.md | 1.0.0 | 2026-01-29 |
336+
| OPENAPI_SPECIFICATION.md | 1.0.0 | 2026-01-29 |
337+
| IMPLEMENTATION_SUMMARY.md | 1.0.0 | 2026-01-29 |
338+
| README.md (this file) | 1.0.0 | 2026-01-29 |
296339

297340
---
298341

@@ -316,6 +359,6 @@ For error handling, check [API_ERRORS.md](./API_ERRORS.md).
316359

317360
---
318361

319-
*Generated: 2026-01-29*
320-
*API Version: 1.0.0*
321-
*Documentation Version: 1.0.0*
362+
_Generated: 2026-01-29_
363+
_API Version: 1.0.0_
364+
_Documentation Version: 1.0.0_

0 commit comments

Comments
 (0)