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
@@ -115,25 +115,15 @@ The above example serves to illustrate some of the process to make a request to
115
115
Regardless of method, you can execute the fetch requests through Umbraco's [tryExecute](https://apidocs.umbraco.com/v16/ui-api/classes/packages_core_auth.UmbAuthContext.html#tryexecute) function. This function will handle any errors that occur during the request and will automatically refresh the token if it is expired. If the session is expired, the function will also make sure the user logs in again.
The `tryExecute` function takes the context of the current class or element as the first argument and the request as the second argument. Therefore, the above example can be used in any class or element that extends from either the [UmbController](https://apidocs.umbraco.com/v16/ui-api/interfaces/libs_controller-api.UmbController.html) or [UmbLitElement](https://apidocs.umbraco.com/v16/ui-api/classes/packages_core_lit-element.UmbLitElement.html) classes.
45
45
46
+
It is recommended to use the `tryExecute` function instead of the raw HTTP client. It can also be configured not to show notifications, if you want to handle errors yourself:
47
+
48
+
```javascript
49
+
tryExecute(this, request, {
50
+
disableNotifications:true,
51
+
});
52
+
```
53
+
54
+
### Cancelling requests
55
+
56
+
The HTTP client also supports cancelling requests. This is useful if you want to cancel a request that is taking too long or if the user navigates away from the page. You can cancel a request by using the [AbortController API](https://developer.mozilla.org/en-US/docs/Web/API/AbortController). The `AbortController` API is a built-in API in modern browsers that allows you to cancel requests. You can use it directly with tryExecute:
57
+
58
+
```javascript
59
+
constabortController=newAbortController();
60
+
61
+
// Cancel the request before starting it for illustration purposes
62
+
abortController.abort();
63
+
64
+
tryExecute(this, request, {
65
+
disableNotifications:true,
66
+
abortSignal:abortController.signal,
67
+
});
68
+
```
69
+
46
70
## Custom Generated Client
47
71
48
72
The HTTP client is generated using the [@hey-api/openapi-ts](https://heyapi.dev/openapi-ts/get-started) library. This library allows anyone to generate a TypeScript client from an OpenAPI specification. The generated client provides a convenient way to make requests to that specific API with type-safety without having to manually write the requests yourself. You can consider generating a client. This can save you a lot of time and effort when working with custom API controllers.
@@ -76,7 +100,7 @@ import { UMB_AUTH_CONTEXT } from '@umbraco-cms/backoffice/auth';
0 commit comments