@zapyapi/sdk 1.0.0-beta.5 → 1.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -1
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/version.d.ts +1 -1
package/README.md
CHANGED
|
@@ -202,12 +202,16 @@ await client.webhooks.deleteConfig();
|
|
|
202
202
|
|
|
203
203
|
## Error Handling
|
|
204
204
|
|
|
205
|
+
The SDK provides detailed error classes for different failure scenarios:
|
|
206
|
+
|
|
205
207
|
```typescript
|
|
206
208
|
import {
|
|
207
209
|
ZapyClient,
|
|
208
210
|
ZapyApiError,
|
|
209
211
|
AuthenticationError,
|
|
210
212
|
RateLimitError,
|
|
213
|
+
NetworkError,
|
|
214
|
+
TimeoutError,
|
|
211
215
|
ValidationError,
|
|
212
216
|
} from '@zapyapi/sdk';
|
|
213
217
|
|
|
@@ -217,17 +221,46 @@ try {
|
|
|
217
221
|
text: 'Hello!',
|
|
218
222
|
});
|
|
219
223
|
} catch (error) {
|
|
220
|
-
if (error instanceof
|
|
224
|
+
if (error instanceof TimeoutError) {
|
|
225
|
+
// Request timed out
|
|
226
|
+
console.error(`Request timed out after ${error.timeout}ms`);
|
|
227
|
+
console.error(`Request: ${error.method} ${error.url}`);
|
|
228
|
+
} else if (error instanceof NetworkError) {
|
|
229
|
+
// Network failure (no response received)
|
|
230
|
+
console.error(`Network error: ${error.message}`);
|
|
231
|
+
console.error(`Error code: ${error.code}`); // e.g., ECONNREFUSED
|
|
232
|
+
} else if (error instanceof AuthenticationError) {
|
|
221
233
|
console.error('Invalid API key');
|
|
222
234
|
} else if (error instanceof RateLimitError) {
|
|
223
235
|
console.error(`Rate limited. Retry after: ${error.retryAfter}ms`);
|
|
236
|
+
console.error(`Retry at: ${error.getRetryAfterDate()}`);
|
|
224
237
|
} else if (error instanceof ZapyApiError) {
|
|
225
238
|
console.error(`API Error [${error.code}]: ${error.message}`);
|
|
239
|
+
console.error(`Status: ${error.statusCode}`);
|
|
226
240
|
console.error(`Request ID: ${error.requestId}`);
|
|
241
|
+
console.error(`Request: ${error.method} ${error.url}`);
|
|
242
|
+
|
|
243
|
+
// For debugging/logging
|
|
244
|
+
console.error(error.toDetailedString());
|
|
245
|
+
// Or serialize to JSON
|
|
246
|
+
console.error(JSON.stringify(error.toJSON(), null, 2));
|
|
227
247
|
}
|
|
228
248
|
}
|
|
229
249
|
```
|
|
230
250
|
|
|
251
|
+
### Error Classes
|
|
252
|
+
|
|
253
|
+
| Error Class | Description |
|
|
254
|
+
|-------------|-------------|
|
|
255
|
+
| `ZapyError` | Base error class for all SDK errors |
|
|
256
|
+
| `ZapyApiError` | API returned an error response (4xx, 5xx) |
|
|
257
|
+
| `AuthenticationError` | Invalid or missing API key (401) |
|
|
258
|
+
| `RateLimitError` | Rate limit exceeded (429) |
|
|
259
|
+
| `NetworkError` | Network failure, no response received |
|
|
260
|
+
| `TimeoutError` | Request timed out |
|
|
261
|
+
| `ValidationError` | Input validation failed |
|
|
262
|
+
| `InstanceNotFoundError` | Instance not found (404) |
|
|
263
|
+
|
|
231
264
|
## Utilities
|
|
232
265
|
|
|
233
266
|
```typescript
|
package/index.cjs
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
package/src/version.d.ts
CHANGED