-
Notifications
You must be signed in to change notification settings - Fork 67
Hub Error Handling and loading status
Error handling in PageForm by Kersom. This is form specific handling of errors that belong to particular fields in form:
PageTable component has build this functionality by itself (along with useHubView - or other views). It will show any error or loading status.
It is recommended to use useGet instead of useGetRequest. useGetRequest should be use only in situation when useGet can not be used, for example when we are writing handler for some action and the action must load some additional data before doing POST (PATCH, PUT...).
useGet reruns every time the URL changes. If the URL is empty, it does not run at all. It returns data (actual loaded data, or undefined if not loaded yet), error (error from API if occured), refresh (handler for refreshing data).
We are using the result of useGet for error handling. Usage:
const { data, error, refresh } = useGet<HubItemsResponse>(
hubAPI/v3/plugin/ansible/search/collection-versions/
);
if (error || data?.data.length == 0) { // For other project it should be for example AwxError return ; }
if (!data) { return ; }
This should be implemented for every use get, but beware of early returning from component, you must first call all hooks, so this return should be done after all hooks are called. Dot forget that if useGet should return some data, which is the case for some details and the data are empty or count 0 (for requests that return list), it should be also handled.
Actions in forms or in PageTable are covered by try catch in the framework itself, so if exception occured, it will be handled.
Those will arise usually in modals. Its recomended to use useGet here. For actions, they must have try catch coverage and manual error handling - for example using error state and displaying the error in the modal.
Loading can be implemented using button - isLoading: <Button key="select" variant="primary" id="select" onClick={() => { void copyToRepositories(); }} isDisabled={selectedRepositories.length == 0} isLoading={isLoading}
PageFramework
PageHeader
PageLayout
PageDashboard
PageDashboardCarousel
PageDetails
PageForm
PageTable
PageTabs
PageToolbar
BulkActionDialog
BulkConfirmationDialog
EmptyState
PageCarousel
ReorderItems
useBreakPoint
useFrameworkTranslations
useInMemoryView
useIsMounted
useOpen
usePageNavigate
useSearchParams
useSelectDialog
useTableItems
useView
useWindowLocation
useDeleteRequest
useGet
useGetAllPagesAWX
useGetItem
useGetRequest
useOptions
usePatchRequest
usePostRequest