|
1 | 1 | import { useCallback, useMemo, useRef, useState } from 'react'; |
2 | 2 |
|
3 | | -import { Optional, SendbirdChatSDK, SendbirdUser, useAsyncEffect } from '@sendbird/uikit-utils'; |
| 3 | +import type { Optional, SendbirdChatSDK, SendbirdUser } from '@sendbird/uikit-utils'; |
| 4 | +import { Logger, SBErrorCode, SBErrorMessage, useAsyncEffect } from '@sendbird/uikit-utils'; |
4 | 5 |
|
5 | 6 | import type { CustomQueryInterface, UseUserListOptions, UseUserListReturn } from '../types'; |
6 | 7 |
|
7 | 8 | const createUserQuery = <User>(sdk: SendbirdChatSDK, queryCreator?: UseUserListOptions<User>['queryCreator']) => { |
8 | 9 | if (queryCreator) return queryCreator(); |
| 10 | + // In order to use the API, the option must be turned on in the dashboard. |
9 | 11 | return sdk.createApplicationUserListQuery() as unknown as CustomQueryInterface<User>; |
10 | 12 | }; |
11 | 13 |
|
@@ -57,7 +59,11 @@ export const useUserList = < |
57 | 59 | const init = useCallback(async () => { |
58 | 60 | query.current = createUserQuery<QueriedUser>(sdk, options?.queryCreator); |
59 | 61 | if (query.current?.hasNext) { |
60 | | - const users = await query.current?.next(); |
| 62 | + const users = await query.current?.next().catch((err) => { |
| 63 | + Logger.error(error); |
| 64 | + if (err.code === SBErrorCode.NON_AUTHORIZED) Logger.warn(SBErrorMessage.ACL); |
| 65 | + throw error; |
| 66 | + }); |
61 | 67 | updateUsers(users, true); |
62 | 68 | } |
63 | 69 | }, [sdk, options?.queryCreator]); |
@@ -88,7 +94,12 @@ export const useUserList = < |
88 | 94 |
|
89 | 95 | const next = useCallback(async () => { |
90 | 96 | if (query.current && query.current?.hasNext) { |
91 | | - updateUsers(await query.current?.next(), false); |
| 97 | + const nextUsers = await query.current.next().catch((err) => { |
| 98 | + Logger.error(error); |
| 99 | + if (err.code === SBErrorCode.NON_AUTHORIZED) Logger.warn(SBErrorMessage.ACL); |
| 100 | + throw error; |
| 101 | + }); |
| 102 | + updateUsers(nextUsers, false); |
92 | 103 | } |
93 | 104 | }, []); |
94 | 105 |
|
|
0 commit comments