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
+52-89Lines changed: 52 additions & 89 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,34 +40,30 @@ Scalar API: Public facing api to manage all scalar platform entities
40
40
<!-- Start SDK Installation [installation] -->
41
41
## SDK Installation
42
42
43
-
> [!TIP]
44
-
> To finish publishing your SDK to npm and others you must [run your first generation action](https://www.speakeasy.com/docs/github-setup#step-by-step-guide).
45
-
46
-
47
43
The SDK can be installed with either [npm](https://www.npmjs.com/), [pnpm](https://pnpm.io/), [bun](https://bun.sh/) or [yarn](https://classic.yarnpkg.com/en/) package managers.
48
44
49
45
### NPM
50
46
51
47
```bash
52
-
npm add <UNSET>
48
+
npm add @scalar/sdk
53
49
```
54
50
55
51
### PNPM
56
52
57
53
```bash
58
-
pnpm add <UNSET>
54
+
pnpm add @scalar/sdk
59
55
```
60
56
61
57
### Bun
62
58
63
59
```bash
64
-
bun add <UNSET>
60
+
bun add @scalar/sdk
65
61
```
66
62
67
63
### Yarn
68
64
69
65
```bash
70
-
yarn add <UNSET> zod
66
+
yarn add @scalar/sdk zod
71
67
72
68
# Note that Yarn does not install peer dependencies automatically. You will need
73
69
# to install zod as shown above.
@@ -184,7 +180,6 @@ async function run() {
184
180
namespace: "<value>",
185
181
});
186
182
187
-
// Handle the result
188
183
console.log(result);
189
184
}
190
185
@@ -217,7 +212,6 @@ async function run() {
217
212
namespace: "<value>",
218
213
});
219
214
220
-
// Handle the result
221
215
console.log(result);
222
216
}
223
217
@@ -380,7 +374,6 @@ async function run() {
380
374
},
381
375
});
382
376
383
-
// Handle the result
384
377
console.log(result);
385
378
}
386
379
@@ -411,7 +404,6 @@ async function run() {
411
404
namespace: "<value>",
412
405
});
413
406
414
-
// Handle the result
415
407
console.log(result);
416
408
}
417
409
@@ -423,88 +415,45 @@ run();
423
415
<!-- Start Error Handling [errors] -->
424
416
## Error Handling
425
417
426
-
Some methods specify known errors which can be thrown. All the known errors are enumerated in the `models/errors/errors.ts` module. The known errors for a method are documented under the *Errors* tables in SDK docs. For example, the `getv1ApisNamespace` method may throw the following errors:
// The server response does not match the expected SDK schema
468
-
case (errinstanceofSDKValidationError): {
469
-
// Pretty-print will provide a human-readable multi-line error message
470
-
console.error(err.pretty());
471
-
// Raw value may also be inspected
472
-
console.error(err.rawValue);
473
-
return;
474
-
}
475
-
case (errinstanceofFourHundred): {
476
-
// Handle err.data$: FourHundredData
477
-
console.error(err);
478
-
return;
479
-
}
480
-
case (errinstanceofFourHundredAndOne): {
481
-
// Handle err.data$: FourHundredAndOneData
482
-
console.error(err);
483
-
return;
484
-
}
485
-
case (errinstanceofFourHundredAndThree): {
486
-
// Handle err.data$: FourHundredAndThreeData
487
-
console.error(err);
488
-
return;
489
-
}
490
-
case (errinstanceofFourHundredAndFour): {
491
-
// Handle err.data$: FourHundredAndFourData
492
-
console.error(err);
493
-
return;
494
-
}
495
-
case (errinstanceofFourHundredAndTwentyTwo): {
496
-
// Handle err.data$: FourHundredAndTwentyTwoData
497
-
console.error(err);
498
-
return;
499
-
}
500
-
case (errinstanceofFiveHundred): {
501
-
// Handle err.data$: FiveHundredData
502
-
console.error(err);
503
-
return;
504
-
}
505
-
default: {
506
-
// Other errors such as network errors, see HTTPClientErrors for more details
507
-
throwerr;
445
+
} catch (error) {
446
+
// The base class for HTTP error responses
447
+
if (errorinstanceoferrors.ScalarError) {
448
+
console.log(error.message);
449
+
console.log(error.statusCode);
450
+
console.log(error.body);
451
+
console.log(error.headers);
452
+
453
+
// Depending on the method different errors may be thrown
454
+
if (errorinstanceoferrors.FourHundred) {
455
+
console.log(error.data$.message); // string
456
+
console.log(error.data$.code); // string
508
457
}
509
458
}
510
459
}
@@ -514,17 +463,32 @@ run();
514
463
515
464
```
516
465
517
-
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.
466
+
### Error Classes
467
+
**Primary errors:**
468
+
*[`ScalarError`](./src/models/errors/scalarerror.ts): The base class for HTTP error responses.
469
+
*[`FourHundred`](docs/models/errors/fourhundred.md): Bad request. Status code `400`.
470
+
*[`FourHundredAndOne`](docs/models/errors/fourhundredandone.md): No auth. Status code `401`.
471
+
*[`FourHundredAndThree`](docs/models/errors/fourhundredandthree.md): Forbidden. Status code `403`.
472
+
*[`FourHundredAndFour`](docs/models/errors/fourhundredandfour.md): Not found. Status code `404`.
473
+
*[`FourHundredAndTwentyTwo`](docs/models/errors/fourhundredandtwentytwo.md): Invalid payload. Status code `422`.
474
+
*[`FiveHundred`](docs/models/errors/fivehundred.md): Uncaught error. Status code `500`.
475
+
476
+
<details><summary>Less common errors (6)</summary>
477
+
478
+
<br />
479
+
480
+
**Network errors:**
481
+
*[`ConnectionError`](./src/models/errors/httpclienterrors.ts): HTTP client was unable to make a request to a server.
482
+
*[`RequestTimeoutError`](./src/models/errors/httpclienterrors.ts): HTTP request timed out due to an AbortSignal signal.
483
+
*[`RequestAbortedError`](./src/models/errors/httpclienterrors.ts): HTTP request was aborted by the client.
484
+
*[`InvalidRequestError`](./src/models/errors/httpclienterrors.ts): Any input used to create a request is invalid.
485
+
*[`UnexpectedClientError`](./src/models/errors/httpclienterrors.ts): Unrecognised or unexpected error.
518
486
519
-
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 `models/errors/httpclienterrors.ts` module:
| RequestAbortedError | HTTP request was aborted by the client |
524
-
| RequestTimeoutError | HTTP request timed out due to an AbortSignal signal |
525
-
| ConnectionError | HTTP client was unable to make a request to a server |
526
-
| InvalidRequestError | Any input used to create a request is invalid |
527
-
| UnexpectedClientError | Unrecognised or unexpected error |
488
+
**Inherit from [`ScalarError`](./src/models/errors/scalarerror.ts)**:
489
+
*[`ResponseValidationError`](./src/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.
0 commit comments