Skip to content

Commit 962d694

Browse files
committed
chore: update ACL message
1 parent 9a925a0 commit 962d694

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

packages/uikit-chat-hooks/src/common/useUserList.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { useCallback, useMemo, useRef, useState } from 'react';
22

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';
45

56
import type { CustomQueryInterface, UseUserListOptions, UseUserListReturn } from '../types';
67

78
const createUserQuery = <User>(sdk: SendbirdChatSDK, queryCreator?: UseUserListOptions<User>['queryCreator']) => {
89
if (queryCreator) return queryCreator();
10+
// In order to use the API, the option must be turned on in the dashboard.
911
return sdk.createApplicationUserListQuery() as unknown as CustomQueryInterface<User>;
1012
};
1113

@@ -57,7 +59,11 @@ export const useUserList = <
5759
const init = useCallback(async () => {
5860
query.current = createUserQuery<QueriedUser>(sdk, options?.queryCreator);
5961
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+
});
6167
updateUsers(users, true);
6268
}
6369
}, [sdk, options?.queryCreator]);
@@ -88,7 +94,12 @@ export const useUserList = <
8894

8995
const next = useCallback(async () => {
9096
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);
92103
}
93104
}, []);
94105

packages/uikit-utils/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ export const NOOP: () => void = () => void 0;
2828
export const ASYNC_NOOP = async () => void 0;
2929
export const PASS = <T>(val: T) => val;
3030
export const toMegabyte = (byte: number) => byte / 1024 / 1024;
31+
export const isFunction = <T>(param?: T): param is NonNullable<T> => typeof param === 'function';
32+
export const SBErrorCode = {
33+
NON_AUTHORIZED: 400108,
34+
};
35+
export const SBErrorMessage = {
36+
ACL:
37+
"An error occurred because you don't have access to the user list in your application.\n" +
38+
'In order to gain access, you can turn on this attribute in the Access Control List settings on Sendbird Dashboard.',
39+
};
3140

3241
export type {
3342
FilterByValueType,

0 commit comments

Comments
 (0)