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
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Error type.
251
+
All SDK methods return a response object or throw an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Error type.
thrownewError("Unexpected status code: "+res?.statusCode||"-");
288
288
}
289
+
290
+
// handle response
289
291
}
290
292
291
293
run();
@@ -304,69 +306,60 @@ You can override the default server globally by passing a server index to the `s
304
306
| - | ------ | --------- |
305
307
| 0 |`http://localhost`| None |
306
308
307
-
#### Example
308
-
309
-
```typescript
310
-
import { SDK } from"@formance/formance-sdk";
311
-
312
-
asyncfunction run() {
313
-
const sdk =newSDK({
314
-
serverIdx: 0,
315
-
authorization: "Bearer <YOUR_ACCESS_TOKEN_HERE>",
316
-
});
317
-
318
-
const res =awaitsdk.getVersions();
319
-
320
-
if (res.statusCode==200) {
321
-
// handle response
322
-
}
323
-
}
324
-
325
-
run();
326
309
327
-
```
328
310
329
311
330
312
### Override Server URL Per-Client
331
313
332
314
The default server can also be overridden globally by passing a URL to the `serverURL: str` optional parameter when initializing the SDK client instance. For example:
333
-
```typescript
334
-
import { SDK } from"@formance/formance-sdk";
315
+
<!-- End Server Selection [server] -->
335
316
336
-
asyncfunction run() {
337
-
const sdk =newSDK({
338
-
serverURL: "http://localhost",
339
-
authorization: "Bearer <YOUR_ACCESS_TOKEN_HERE>",
340
-
});
317
+
<!-- Start Custom HTTP Client [http-client] -->
318
+
## Custom HTTP Client
341
319
342
-
const res =awaitsdk.getVersions();
320
+
The TypeScript SDK makes API calls using an `HTTPClient` that wraps the native
321
+
[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). This
322
+
client is a thin wrapper around `fetch` and provides the ability to attach hooks
323
+
around the request lifecycle that can be used to modify the request or handle
324
+
errors and response.
343
325
344
-
if (res.statusCode==200) {
345
-
// handle response
346
-
}
347
-
}
326
+
The `HTTPClient` constructor takes an optional `fetcher` argument that can be
327
+
used to integrate a third-party HTTP client or when writing tests to mock out
328
+
the HTTP client and feed in fixtures.
348
329
349
-
run();
330
+
The following example shows how to use the `"beforeRequest"` hook to to add a
331
+
custom header and a timeout to requests and how to use the `"requestError"` hook
// fetcher takes a function that has the same signature as native `fetch`.
340
+
fetcher: (request) => {
341
+
returnfetch(request);
342
+
}
343
+
});
356
344
357
-
The Typescript SDK makes API calls using the [axios](https://axios-http.com/docs/intro) HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom `AxiosInstance` object.
|`contentType`|*string*|:heavy_check_mark:| HTTP response content type for this operation |
10
10
|`statusCode`|*number*|:heavy_check_mark:| HTTP response status code for this operation |
11
-
|`rawResponse`|[AxiosResponse](https://axios-http.com/docs/res_schema)|:heavy_check_mark:| Raw HTTP response; suitable for custom response parsing |
11
+
|`rawResponse`|[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)|:heavy_check_mark:| Raw HTTP response; suitable for custom response parsing |
|`contentType`|*string*|:heavy_check_mark:| HTTP response content type for this operation|
9
+
|`statusCode`|*number*|:heavy_check_mark:| HTTP response status code for this operation|
10
+
|`rawResponse`|[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)|:heavy_check_mark:| Raw HTTP response; suitable for custom response parsing|
|`statusCode`|*number*|:heavy_check_mark:| HTTP response status code for this operation|
11
+
|`rawResponse`|[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)|:heavy_check_mark:| Raw HTTP response; suitable for custom response parsing|
|`statusCode`|*number*|:heavy_check_mark:| HTTP response status code for this operation|
11
+
|`rawResponse`|[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)|:heavy_check_mark:| Raw HTTP response; suitable for custom response parsing|
0 commit comments