Skip to content

Commit

Permalink
chore: update ACL message
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Oct 25, 2022
1 parent 9a925a0 commit 962d694
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/uikit-chat-hooks/src/common/useUserList.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useCallback, useMemo, useRef, useState } from 'react';

import { Optional, SendbirdChatSDK, SendbirdUser, useAsyncEffect } from '@sendbird/uikit-utils';
import type { Optional, SendbirdChatSDK, SendbirdUser } from '@sendbird/uikit-utils';
import { Logger, SBErrorCode, SBErrorMessage, useAsyncEffect } from '@sendbird/uikit-utils';

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

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

Expand Down Expand Up @@ -57,7 +59,11 @@ export const useUserList = <
const init = useCallback(async () => {
query.current = createUserQuery<QueriedUser>(sdk, options?.queryCreator);
if (query.current?.hasNext) {
const users = await query.current?.next();
const users = await query.current?.next().catch((err) => {
Logger.error(error);
if (err.code === SBErrorCode.NON_AUTHORIZED) Logger.warn(SBErrorMessage.ACL);
throw error;
});
updateUsers(users, true);
}
}, [sdk, options?.queryCreator]);
Expand Down Expand Up @@ -88,7 +94,12 @@ export const useUserList = <

const next = useCallback(async () => {
if (query.current && query.current?.hasNext) {
updateUsers(await query.current?.next(), false);
const nextUsers = await query.current.next().catch((err) => {
Logger.error(error);
if (err.code === SBErrorCode.NON_AUTHORIZED) Logger.warn(SBErrorMessage.ACL);
throw error;
});
updateUsers(nextUsers, false);
}
}, []);

Expand Down
9 changes: 9 additions & 0 deletions packages/uikit-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ export const NOOP: () => void = () => void 0;
export const ASYNC_NOOP = async () => void 0;
export const PASS = <T>(val: T) => val;
export const toMegabyte = (byte: number) => byte / 1024 / 1024;
export const isFunction = <T>(param?: T): param is NonNullable<T> => typeof param === 'function';
export const SBErrorCode = {
NON_AUTHORIZED: 400108,
};
export const SBErrorMessage = {
ACL:
"An error occurred because you don't have access to the user list in your application.\n" +
'In order to gain access, you can turn on this attribute in the Access Control List settings on Sendbird Dashboard.',
};

export type {
FilterByValueType,
Expand Down

0 comments on commit 962d694

Please sign in to comment.