Skip to content

Commit e2a32e1

Browse files
committed
docs: update error contract to { error, code } matching API changes
1 parent fdf5cd7 commit e2a32e1

3 files changed

Lines changed: 39 additions & 12 deletions

File tree

AGENTS.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,34 @@ const { data } = await roxy.crystals.searchCrystals({
8585

8686
### Error handling
8787

88+
All errors return `{ error: string, code: string }`. The `error` field is human-readable (may change wording). The `code` field is machine-readable (stable, safe to switch on).
89+
8890
```typescript
8991
const { data, error, response } = await roxy.astrology.getDailyHoroscope({
9092
path: { sign: 'aries' },
9193
});
9294

9395
if (error) {
94-
// error is { error: string } on 4xx/5xx
95-
console.error('Status:', response?.status, 'Error:', error);
96+
// error is { error: string, code: string } on 4xx/5xx
97+
console.error('Code:', error.code, 'Message:', error.error);
9698
return;
9799
}
98100
// data is fully typed after error check
99101
console.log(data.sign, data.overview);
100102
```
101103

102-
Common error codes: `401` invalid/missing API key, `403` subscription expired or limit reached, `429` rate limited, `404` resource not found.
104+
Error codes:
105+
106+
| Status | Code | When |
107+
|--------|------|------|
108+
| 400 | `validation_error` | Missing or invalid parameters |
109+
| 401 | `api_key_required` | No API key provided |
110+
| 401 | `invalid_api_key` | Key format invalid or tampered |
111+
| 401 | `subscription_not_found` | Key references non-existent subscription |
112+
| 401 | `subscription_inactive` | Subscription cancelled, expired, or suspended |
113+
| 404 | `not_found` | Resource not found |
114+
| 429 | `rate_limit_exceeded` | Monthly quota reached |
115+
| 500 | `internal_error` | Server error |
103116

104117
## Common tasks
105118

@@ -142,6 +155,7 @@ const city = cities[0];
142155
- **Date format is `YYYY-MM-DD`, time is `HH:MM:SS`.** Both are strings. Timezone is optional (IANA format like `America/New_York`).
143156
- **All list endpoints may return paginated objects** (e.g. `{ items: [...], total: N }`) rather than raw arrays. Check the type.
144157
- **`data` and `error` are mutually exclusive.** If `error` is set, `data` is `undefined` and vice versa.
158+
- **Errors have `error` (message) and `code` (machine-readable).** Switch on `code`, not `error` — the message may change wording.
145159

146160
## Links
147161

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ const roxy = new Roxy({ client });
9191

9292
## Error handling
9393

94-
Every method returns `{ data, error, response }`. Check `error` for API errors, or enable `throwOnError` to throw instead.
94+
Every method returns `{ data, error, response }`. Errors have `{ error: string, code: string }` — switch on `code` for programmatic handling.
9595

9696
```typescript
9797
const { data, error } = await roxy.astrology.getZodiacSign({
9898
path: { identifier: 'aries' },
9999
});
100100

101101
if (error) {
102-
console.error(error);
102+
console.error(error.code, error.error); // e.g. "not_found", "Zodiac sign 'xyz' not found"
103103
} else {
104104
console.log(data);
105105
}

docs/llms-full.txt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -644,15 +644,21 @@ const { data } = await roxy.usage.getUsageStats();
644644

645645
## Error Handling
646646

647-
Every method returns `{ data, error, response }`:
647+
Every method returns `{ data, error, response }`. All errors have `{ error: string, code: string }`:
648+
- `error` — human-readable message (may change wording, do not parse)
649+
- `code` — machine-readable identifier (stable, safe to switch on)
648650

649651
```typescript
650652
const { data, error, response } = await roxy.astrology.getDailyHoroscope({
651653
path: { sign: 'aries' },
652654
});
653655

654656
if (error) {
655-
console.error('API error:', error);
657+
// Switch on error.code for programmatic handling
658+
if (error.code === 'rate_limit_exceeded') {
659+
// wait and retry
660+
}
661+
console.error('Code:', error.code, 'Message:', error.error);
656662
console.error('Status:', response?.status);
657663
return;
658664
}
@@ -661,11 +667,18 @@ if (error) {
661667
console.log(data.sign, data.overview);
662668
```
663669

664-
Common errors:
665-
- `401` — Invalid or missing API key
666-
- `403` — Subscription expired or limit reached
667-
- `404` — Resource not found (invalid sign, id, etc.)
668-
- `429` — Rate limited
670+
Error codes:
671+
672+
| Status | Code | When |
673+
|--------|------|------|
674+
| 400 | `validation_error` | Missing or invalid parameters |
675+
| 401 | `api_key_required` | No API key provided |
676+
| 401 | `invalid_api_key` | Key format invalid or tampered |
677+
| 401 | `subscription_not_found` | Key references non-existent subscription |
678+
| 401 | `subscription_inactive` | Subscription cancelled, expired, or suspended |
679+
| 404 | `not_found` | Resource not found |
680+
| 429 | `rate_limit_exceeded` | Monthly quota reached |
681+
| 500 | `internal_error` | Server error |
669682

670683
## Advanced Client Configuration
671684

0 commit comments

Comments
 (0)