You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+51-45Lines changed: 51 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -334,21 +334,21 @@ run();
334
334
<!-- Start Error Handling [errors] -->
335
335
## Error Handling
336
336
337
-
Some methods specify known errors which can be thrown. All the known errors are enumerated in the `sdk/models/errors/errors.ts` module. The known errors for a method are documented under the *Errors* tables in SDK docs. For example, the `createRemoteSource` method may throw the following errors:
337
+
[`SpeakeasyError`](./src/sdk/models/errors/speakeasyerror.ts) is the base class for all HTTP error responses. It has the following properties:
@@ -359,24 +359,18 @@ const speakeasy = new Speakeasy({
359
359
asyncfunction run() {
360
360
try {
361
361
awaitspeakeasy.artifacts.createRemoteSource();
362
-
} catch (err) {
363
-
switch (true) {
364
-
// The server response does not match the expected SDK schema
365
-
case (errinstanceofSDKValidationError): {
366
-
// Pretty-print will provide a human-readable multi-line error message
367
-
console.error(err.pretty());
368
-
// Raw value may also be inspected
369
-
console.error(err.rawValue);
370
-
return;
371
-
}
372
-
case (errinstanceofErrorT): {
373
-
// Handle err.data$: ErrorTData
374
-
console.error(err);
375
-
return;
376
-
}
377
-
default: {
378
-
// Other errors such as network errors, see HTTPClientErrors for more details
379
-
throwerr;
362
+
} catch (error) {
363
+
// The base class for HTTP error responses
364
+
if (errorinstanceoferrors.SpeakeasyError) {
365
+
console.log(error.message);
366
+
console.log(error.statusCode);
367
+
console.log(error.body);
368
+
console.log(error.headers);
369
+
370
+
// Depending on the method different errors may be thrown
371
+
if (errorinstanceoferrors.ErrorT) {
372
+
console.log(error.data$.message); // string
373
+
console.log(error.data$.statusCode); // number
380
374
}
381
375
}
382
376
}
@@ -386,17 +380,29 @@ run();
386
380
387
381
```
388
382
389
-
Validation errors can also occur when either method arguments or data returned from the server do not match the expected format. The `SDKValidationError` that is thrown as a result will capture the raw value that failed validation in an attribute called `rawValue`. Additionally, a `pretty()` method is available on this error that can be used to log a nicely formatted multi-line string since validation errors can list many issues and the plain error string may be difficult read when debugging.
383
+
### Error Classes
384
+
**Primary errors:**
385
+
*[`SpeakeasyError`](./src/sdk/models/errors/speakeasyerror.ts): The base class for HTTP error responses.
386
+
*[`ErrorT`](docs/sdk/models/errors/errort.md): The `Status` type defines a logical error model. *
387
+
388
+
<details><summary>Less common errors (6)</summary>
389
+
390
+
<br />
390
391
391
-
In some rare cases, the SDK can fail to get a response from the server or even make the request due to unexpected circumstances such as network conditions. These types of errors are captured in the `sdk/models/errors/httpclienterrors.ts` module:
392
+
**Network errors:**
393
+
*[`ConnectionError`](./src/sdk/models/errors/httpclienterrors.ts): HTTP client was unable to make a request to a server.
394
+
*[`RequestTimeoutError`](./src/sdk/models/errors/httpclienterrors.ts): HTTP request timed out due to an AbortSignal signal.
395
+
*[`RequestAbortedError`](./src/sdk/models/errors/httpclienterrors.ts): HTTP request was aborted by the client.
396
+
*[`InvalidRequestError`](./src/sdk/models/errors/httpclienterrors.ts): Any input used to create a request is invalid.
397
+
*[`UnexpectedClientError`](./src/sdk/models/errors/httpclienterrors.ts): Unrecognised or unexpected error.
| RequestAbortedError | HTTP request was aborted by the client |
396
-
| RequestTimeoutError | HTTP request timed out due to an AbortSignal signal |
397
-
| ConnectionError | HTTP client was unable to make a request to a server |
398
-
| InvalidRequestError | Any input used to create a request is invalid |
399
-
| UnexpectedClientError | Unrecognised or unexpected error |
399
+
400
+
**Inherit from [`SpeakeasyError`](./src/sdk/models/errors/speakeasyerror.ts)**:
401
+
*[`ResponseValidationError`](./src/sdk/models/errors/responsevalidationerror.ts): Type mismatch between the data returned from the server and the structure expected by the SDK. See `error.rawValue` for the raw value and `error.pretty()` for a nicely formatted multi-line string.
402
+
403
+
</details>
404
+
405
+
\* Check [the method documentation](#available-resources-and-operations) to see if the error is applicable.
400
406
<!-- End Error Handling [errors] -->
401
407
402
408
@@ -408,9 +414,9 @@ In some rare cases, the SDK can fail to get a response from the server or even m
408
414
409
415
You can override the default server globally by passing a server name to the `server: keyof typeof ServerList` optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:
0 commit comments