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
@@ -1011,9 +1010,9 @@ Here's an example of one such pagination call:
1011
1010
import { Apideck } from"@apideck/unify";
1012
1011
1013
1012
const apideck =newApideck({
1014
-
apiKey: process.env["APIDECK_API_KEY"] ??"",
1015
1013
consumerId: "test-consumer",
1016
1014
appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
1015
+
apiKey: process.env["APIDECK_API_KEY"] ??"",
1017
1016
});
1018
1017
1019
1018
asyncfunction run() {
@@ -1033,7 +1032,6 @@ async function run() {
1033
1032
});
1034
1033
1035
1034
forawait (const page ofresult) {
1036
-
// Handle the page
1037
1035
console.log(page);
1038
1036
}
1039
1037
}
@@ -1062,9 +1060,9 @@ import { Apideck } from "@apideck/unify";
1062
1060
import { openAsBlob } from"node:fs";
1063
1061
1064
1062
const apideck =newApideck({
1065
-
apiKey: process.env["APIDECK_API_KEY"] ??"",
1066
1063
consumerId: "test-consumer",
1067
1064
appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
1065
+
apiKey: process.env["APIDECK_API_KEY"] ??"",
1068
1066
});
1069
1067
1070
1068
asyncfunction run() {
@@ -1077,7 +1075,6 @@ async function run() {
1077
1075
requestBody: awaitopenAsBlob("example.file"),
1078
1076
});
1079
1077
1080
-
// Handle the result
1081
1078
console.log(result);
1082
1079
}
1083
1080
@@ -1096,9 +1093,9 @@ To change the default retry strategy for a single API call, simply provide a ret
1096
1093
import { Apideck } from"@apideck/unify";
1097
1094
1098
1095
const apideck =newApideck({
1099
-
apiKey: process.env["APIDECK_API_KEY"] ??"",
1100
1096
consumerId: "test-consumer",
1101
1097
appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
1098
+
apiKey: process.env["APIDECK_API_KEY"] ??"",
1102
1099
});
1103
1100
1104
1101
asyncfunction run() {
@@ -1129,7 +1126,6 @@ async function run() {
1129
1126
});
1130
1127
1131
1128
forawait (const page ofresult) {
1132
-
// Handle the page
1133
1129
console.log(page);
1134
1130
}
1135
1131
}
@@ -1153,9 +1149,9 @@ const apideck = new Apideck({
1153
1149
},
1154
1150
retryConnectionErrors: false,
1155
1151
},
1156
-
apiKey: process.env["APIDECK_API_KEY"] ??"",
1157
1152
consumerId: "test-consumer",
1158
1153
appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
1154
+
apiKey: process.env["APIDECK_API_KEY"] ??"",
1159
1155
});
1160
1156
1161
1157
asyncfunction run() {
@@ -1175,7 +1171,6 @@ async function run() {
1175
1171
});
1176
1172
1177
1173
forawait (const page ofresult) {
1178
-
// Handle the page
1179
1174
console.log(page);
1180
1175
}
1181
1176
}
@@ -1188,40 +1183,29 @@ run();
1188
1183
<!-- Start Error Handling [errors] -->
1189
1184
## Error Handling
1190
1185
1191
-
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 `list` method may throw the following errors:
1186
+
[`ApideckError`](./src/models/errors/apideckerror.ts) is the base class for all HTTP error responses. It has the following properties:
// The server response does not match the expected SDK schema
1246
-
case (errinstanceofSDKValidationError): {
1247
-
// Pretty-print will provide a human-readable multi-line error message
1248
-
console.error(err.pretty());
1249
-
// Raw value may also be inspected
1250
-
console.error(err.rawValue);
1251
-
return;
1252
-
}
1253
-
case (errinstanceofBadRequestResponse): {
1254
-
// Handle err.data$: BadRequestResponseData
1255
-
console.error(err);
1256
-
return;
1257
-
}
1258
-
case (errinstanceofUnauthorizedResponse): {
1259
-
// Handle err.data$: UnauthorizedResponseData
1260
-
console.error(err);
1261
-
return;
1262
-
}
1263
-
case (errinstanceofPaymentRequiredResponse): {
1264
-
// Handle err.data$: PaymentRequiredResponseData
1265
-
console.error(err);
1266
-
return;
1267
-
}
1268
-
case (errinstanceofNotFoundResponse): {
1269
-
// Handle err.data$: NotFoundResponseData
1270
-
console.error(err);
1271
-
return;
1272
-
}
1273
-
case (errinstanceofUnprocessableResponse): {
1274
-
// Handle err.data$: UnprocessableResponseData
1275
-
console.error(err);
1276
-
return;
1277
-
}
1278
-
default: {
1279
-
// Other errors such as network errors, see HTTPClientErrors for more details
1280
-
throwerr;
1226
+
} catch (error) {
1227
+
// The base class for HTTP error responses
1228
+
if (errorinstanceoferrors.ApideckError) {
1229
+
console.log(error.message);
1230
+
console.log(error.httpMeta.response.status);
1231
+
console.log(error.httpMeta.response.headers);
1232
+
console.log(error.httpMeta.request);
1233
+
1234
+
// Depending on the method different errors may be thrown
1235
+
if (errorinstanceoferrors.BadRequestResponse) {
1236
+
console.log(error.data$.statusCode); // number
1237
+
console.log(error.data$.error); // string
1238
+
console.log(error.data$.typeName); // string
1239
+
console.log(error.data$.message); // string
1240
+
console.log(error.data$.detail); // errors.Detail
1281
1241
}
1282
1242
}
1283
1243
}
@@ -1287,17 +1247,33 @@ run();
1287
1247
1288
1248
```
1289
1249
1290
-
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.
1250
+
### Error Classes
1251
+
**Primary errors:**
1252
+
*[`ApideckError`](./src/models/errors/apideckerror.ts): The base class for HTTP error responses.
1253
+
*[`UnauthorizedResponse`](docs/models/errors/unauthorizedresponse.md): Unauthorized. Status code `401`.
1254
+
*[`PaymentRequiredResponse`](docs/models/errors/paymentrequiredresponse.md): Payment Required. Status code `402`.
1255
+
*[`NotFoundResponse`](docs/models/errors/notfoundresponse.md): The specified resource was not found. Status code `404`. *
1256
+
*[`BadRequestResponse`](docs/models/errors/badrequestresponse.md): Bad Request. Status code `400`. *
1257
+
*[`UnprocessableResponse`](docs/models/errors/unprocessableresponse.md): Unprocessable. Status code `422`. *
1258
+
1259
+
<details><summary>Less common errors (6)</summary>
1260
+
1261
+
<br />
1262
+
1263
+
**Network errors:**
1264
+
*[`ConnectionError`](./src/models/errors/httpclienterrors.ts): HTTP client was unable to make a request to a server.
1265
+
*[`RequestTimeoutError`](./src/models/errors/httpclienterrors.ts): HTTP request timed out due to an AbortSignal signal.
1266
+
*[`RequestAbortedError`](./src/models/errors/httpclienterrors.ts): HTTP request was aborted by the client.
1267
+
*[`InvalidRequestError`](./src/models/errors/httpclienterrors.ts): Any input used to create a request is invalid.
1268
+
*[`UnexpectedClientError`](./src/models/errors/httpclienterrors.ts): Unrecognised or unexpected error.
1291
1269
1292
-
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 |
1297
-
| RequestTimeoutError | HTTP request timed out due to an AbortSignal signal |
1298
-
| ConnectionError | HTTP client was unable to make a request to a server |
1299
-
| InvalidRequestError | Any input used to create a request is invalid |
1300
-
| UnexpectedClientError | Unrecognised or unexpected error |
1271
+
**Inherit from [`ApideckError`](./src/models/errors/apideckerror.ts)**:
1272
+
*[`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.
1273
+
1274
+
</details>
1275
+
1276
+
\* Check [the method documentation](#available-resources-and-operations) to see if the error is applicable.
1301
1277
<!-- End Error Handling [errors] -->
1302
1278
1303
1279
<!-- Start Server Selection [server] -->
@@ -1311,9 +1287,9 @@ import { Apideck } from "@apideck/unify";
1311
1287
1312
1288
const apideck =newApideck({
1313
1289
serverURL: "https://unify.apideck.com",
1314
-
apiKey: process.env["APIDECK_API_KEY"] ??"",
1315
1290
consumerId: "test-consumer",
1316
1291
appId: "dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
1292
+
apiKey: process.env["APIDECK_API_KEY"] ??"",
1317
1293
});
1318
1294
1319
1295
asyncfunction run() {
@@ -1333,7 +1309,6 @@ async function run() {
1333
1309
});
1334
1310
1335
1311
forawait (const page ofresult) {
1336
-
// Handle the page
1337
1312
console.log(page);
1338
1313
}
1339
1314
}
@@ -1350,9 +1325,9 @@ import { Apideck } from "@apideck/unify";
0 commit comments