Skip to content

Commit

Permalink
fix(shared): Return api errors from organization hooks (#2743)
Browse files Browse the repository at this point in the history
* fix(shared): Return api errors from organization hooks

* fix(shared): Update changeset to minor
  • Loading branch information
panteliselef authored Feb 8, 2024
1 parent 37b4159 commit 8daf845
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sixty-lions-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': minor
---

Add `error` for each paginated property return by `useOrganization` and `useOrganizationList` hooks.
1 change: 1 addition & 0 deletions packages/shared/src/react/hooks/useOrganization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type UseOrganization = <T extends UseOrganizationParams>(
const undefinedPaginatedResource = {
data: undefined,
count: undefined,
error: undefined,
isLoading: false,
isFetching: false,
isError: false,
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/react/hooks/useOrganizationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type UseOrganizationListParams = {
const undefinedPaginatedResource = {
data: undefined,
count: undefined,
error: undefined,
isLoading: false,
isFetching: false,
isError: false,
Expand Down
4 changes: 3 additions & 1 deletion packages/shared/src/react/hooks/usePagesOrInfinite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ export const usePagesOrInfinite: UsePagesOrInfinite = (params, fetcher, config,

const isLoading = triggerInfinite ? swrInfiniteIsLoading : swrIsLoading;
const isFetching = triggerInfinite ? swrInfiniteIsValidating : swrIsValidating;
const isError = !!(triggerInfinite ? swrInfiniteError : swrError);
const error = (triggerInfinite ? swrInfiniteError : swrError) ?? null;
const isError = !!error;
/**
* Helpers
*/
Expand Down Expand Up @@ -207,6 +208,7 @@ export const usePagesOrInfinite: UsePagesOrInfinite = (params, fetcher, config,
return {
data,
count,
error,
isLoading,
isFetching,
isError,
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/react/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { ClerkPaginatedResponse } from '@clerk/types';

import type { ClerkAPIResponseError } from '../error';

export type ValueOrSetter<T = unknown> = (size: T | ((_size: T) => T)) => void;

export type CacheSetter<CData = any> = (
Expand All @@ -9,6 +11,7 @@ export type CacheSetter<CData = any> = (
export type PaginatedResources<T = unknown, Infinite = false> = {
data: T[];
count: number;
error: ClerkAPIResponseError | null;
isLoading: boolean;
isFetching: boolean;
isError: boolean;
Expand Down

0 comments on commit 8daf845

Please sign in to comment.