Skip to content

Commit 8daf845

Browse files
authored
fix(shared): Return api errors from organization hooks (clerk#2743)
* fix(shared): Return api errors from organization hooks * fix(shared): Update changeset to minor
1 parent 37b4159 commit 8daf845

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

.changeset/sixty-lions-obey.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/shared': minor
3+
---
4+
5+
Add `error` for each paginated property return by `useOrganization` and `useOrganizationList` hooks.

packages/shared/src/react/hooks/useOrganization.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type UseOrganization = <T extends UseOrganizationParams>(
7373
const undefinedPaginatedResource = {
7474
data: undefined,
7575
count: undefined,
76+
error: undefined,
7677
isLoading: false,
7778
isFetching: false,
7879
isError: false,

packages/shared/src/react/hooks/useOrganizationList.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type UseOrganizationListParams = {
2424
const undefinedPaginatedResource = {
2525
data: undefined,
2626
count: undefined,
27+
error: undefined,
2728
isLoading: false,
2829
isFetching: false,
2930
isError: false,

packages/shared/src/react/hooks/usePagesOrInfinite.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ export const usePagesOrInfinite: UsePagesOrInfinite = (params, fetcher, config,
174174

175175
const isLoading = triggerInfinite ? swrInfiniteIsLoading : swrIsLoading;
176176
const isFetching = triggerInfinite ? swrInfiniteIsValidating : swrIsValidating;
177-
const isError = !!(triggerInfinite ? swrInfiniteError : swrError);
177+
const error = (triggerInfinite ? swrInfiniteError : swrError) ?? null;
178+
const isError = !!error;
178179
/**
179180
* Helpers
180181
*/
@@ -207,6 +208,7 @@ export const usePagesOrInfinite: UsePagesOrInfinite = (params, fetcher, config,
207208
return {
208209
data,
209210
count,
211+
error,
210212
isLoading,
211213
isFetching,
212214
isError,

packages/shared/src/react/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { ClerkPaginatedResponse } from '@clerk/types';
22

3+
import type { ClerkAPIResponseError } from '../error';
4+
35
export type ValueOrSetter<T = unknown> = (size: T | ((_size: T) => T)) => void;
46

57
export type CacheSetter<CData = any> = (
@@ -9,6 +11,7 @@ export type CacheSetter<CData = any> = (
911
export type PaginatedResources<T = unknown, Infinite = false> = {
1012
data: T[];
1113
count: number;
14+
error: ClerkAPIResponseError | null;
1215
isLoading: boolean;
1316
isFetching: boolean;
1417
isError: boolean;

0 commit comments

Comments
 (0)